0

OnTask: unified boca enums with ontask enums

This CL replaces the OnTaskBlockList::RestrictionLevel
enums with the ones from the boca bundle.

Bug: b:373548379
Change-Id: Ib1d8fa2334ba0e113f10e509044d49289eacf895
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5954115
Commit-Queue: Matthew Zhu <zhumatthew@google.com>
Reviewed-by: Vignesh Shenvi <vshenvi@google.com>
Cr-Commit-Position: refs/heads/main@{#1372825}
This commit is contained in:
zhumatthew
2024-10-23 17:40:53 +00:00
committed by Chromium LUCI CQ
parent 15fbbb6277
commit 1e834ecfbe
12 changed files with 215 additions and 212 deletions

@@ -23,7 +23,8 @@
namespace ash { // namespace namespace ash { // namespace
namespace { namespace {
using RestrictionLevel = OnTaskBlocklist::RestrictionLevel;
using ::boca::LockedNavigationOptions;
// Returns whether all the given query parameters are found in the URL. // Returns whether all the given query parameters are found in the URL.
bool DoAllQueryParamsExist(const std::set<std::string>& request_params, bool DoAllQueryParamsExist(const std::set<std::string>& request_params,
@@ -117,7 +118,7 @@ bool OnTaskLockedSessionNavigationThrottle::MaybeProceedForOneLevelDeep(
} }
on_task_blocklist->MaybeSetURLRestrictionLevel( on_task_blocklist->MaybeSetURLRestrictionLevel(
navigation_handle()->GetWebContents(), url, navigation_handle()->GetWebContents(), url,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
return true; return true;
} }
@@ -227,13 +228,14 @@ OnTaskLockedSessionNavigationThrottle::CheckRestrictions() {
// exact URL for subsequent navigations. The exact URL matching will occur // exact URL for subsequent navigations. The exact URL matching will occur
// in `on_task_blocklist->CanPerformOneLevelNavigation()`. // in `on_task_blocklist->CanPerformOneLevelNavigation()`.
if (on_task_blocklist->current_page_restriction_level() == if (on_task_blocklist->current_page_restriction_level() ==
RestrictionLevel::kOneLevelDeepNavigation) { LockedNavigationOptions::LIMITED_NAVIGATION) {
if (!MaybeProceedForOneLevelDeep(on_task_blocklist->previous_tab(), if (!MaybeProceedForOneLevelDeep(on_task_blocklist->previous_tab(),
url)) { url)) {
return content::NavigationThrottle::CANCEL; return content::NavigationThrottle::CANCEL;
} }
} else if (on_task_blocklist->current_page_restriction_level() == } else if (on_task_blocklist->current_page_restriction_level() ==
RestrictionLevel::kDomainAndOneLevelDeepNavigation) { LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION) {
// Similar conditions as the above, but we first check if it's the same // Similar conditions as the above, but we first check if it's the same
// domain first before checking the one level deep case since we allow // domain first before checking the one level deep case since we allow
// same domain navigations as well. // same domain navigations as well.
@@ -254,7 +256,8 @@ OnTaskLockedSessionNavigationThrottle::CheckRestrictions() {
if (url.DomainIs(source_url.host())) { if (url.DomainIs(source_url.host())) {
on_task_blocklist->MaybeSetURLRestrictionLevel( on_task_blocklist->MaybeSetURLRestrictionLevel(
navigation_handle()->GetWebContents(), url, navigation_handle()->GetWebContents(), url,
RestrictionLevel::kDomainAndOneLevelDeepNavigation); LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
} else { } else {
if (!MaybeProceedForOneLevelDeep( if (!MaybeProceedForOneLevelDeep(
navigation_handle()->GetWebContents(), url)) { navigation_handle()->GetWebContents(), url)) {

@@ -30,6 +30,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
using ash::boca::OnTaskSystemWebAppManagerImpl; using ash::boca::OnTaskSystemWebAppManagerImpl;
using ::boca::LockedNavigationOptions;
using ::testing::IsNull; using ::testing::IsNull;
using ::testing::NotNull; using ::testing::NotNull;
@@ -121,11 +122,9 @@ IN_PROC_BROWSER_TEST_F(OnTaskLockedSessionWindowTrackerBrowserTest,
// Spawn two tabs for testing purposes (outside the homepage tab). // Spawn two tabs for testing purposes (outside the homepage tab).
system_web_app_manager()->CreateBackgroundTabWithUrl( system_web_app_manager()->CreateBackgroundTabWithUrl(
window_id, GURL(kTabUrl1), window_id, GURL(kTabUrl1), LockedNavigationOptions::OPEN_NAVIGATION);
OnTaskBlocklist::RestrictionLevel::kNoRestrictions);
system_web_app_manager()->CreateBackgroundTabWithUrl( system_web_app_manager()->CreateBackgroundTabWithUrl(
window_id, GURL(kTabUrl2), window_id, GURL(kTabUrl2), LockedNavigationOptions::OPEN_NAVIGATION);
OnTaskBlocklist::RestrictionLevel::kNoRestrictions);
ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 3); ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 3);
// Close all tabs and verify that the app window is closed. // Close all tabs and verify that the app window is closed.
@@ -155,7 +154,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskLockedSessionWindowTrackerBrowserTest,
// Spawns a tab for testing purposes (outside the homepage tab). // Spawns a tab for testing purposes (outside the homepage tab).
const GURL base_url(kTabUrl1); const GURL base_url(kTabUrl1);
system_web_app_manager()->CreateBackgroundTabWithUrl( system_web_app_manager()->CreateBackgroundTabWithUrl(
window_id, base_url, OnTaskBlocklist::RestrictionLevel::kNoRestrictions); window_id, base_url, LockedNavigationOptions::OPEN_NAVIGATION);
ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2); ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2);
boca_app_browser->tab_strip_model()->ActivateTabAt(1); boca_app_browser->tab_strip_model()->ActivateTabAt(1);
@@ -192,7 +191,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskLockedSessionWindowTrackerBrowserTest,
// Spawns a tab for testing purposes (outside the homepage tab). // Spawns a tab for testing purposes (outside the homepage tab).
const GURL base_url(kTabUrl1); const GURL base_url(kTabUrl1);
system_web_app_manager()->CreateBackgroundTabWithUrl( system_web_app_manager()->CreateBackgroundTabWithUrl(
window_id, base_url, OnTaskBlocklist::RestrictionLevel::kNoRestrictions); window_id, base_url, LockedNavigationOptions::OPEN_NAVIGATION);
ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2); ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2);
boca_app_browser->tab_strip_model()->ActivateTabAt(1); boca_app_browser->tab_strip_model()->ActivateTabAt(1);
@@ -229,7 +228,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskLockedSessionWindowTrackerBrowserTest,
// Spawns a tab for testing purposes (outside the homepage tab). // Spawns a tab for testing purposes (outside the homepage tab).
const GURL base_url(kTabUrl1); const GURL base_url(kTabUrl1);
system_web_app_manager()->CreateBackgroundTabWithUrl( system_web_app_manager()->CreateBackgroundTabWithUrl(
window_id, base_url, OnTaskBlocklist::RestrictionLevel::kNoRestrictions); window_id, base_url, LockedNavigationOptions::OPEN_NAVIGATION);
ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2); ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2);
boca_app_browser->tab_strip_model()->ActivateTabAt(1); boca_app_browser->tab_strip_model()->ActivateTabAt(1);
@@ -266,7 +265,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskLockedSessionWindowTrackerBrowserTest,
// Spawns a tab for testing purposes (outside the homepage tab). // Spawns a tab for testing purposes (outside the homepage tab).
const GURL base_url(kTabUrl1); const GURL base_url(kTabUrl1);
system_web_app_manager()->CreateBackgroundTabWithUrl( system_web_app_manager()->CreateBackgroundTabWithUrl(
window_id, base_url, OnTaskBlocklist::RestrictionLevel::kNoRestrictions); window_id, base_url, LockedNavigationOptions::OPEN_NAVIGATION);
ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2); ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2);
boca_app_browser->tab_strip_model()->ActivateTabAt(1); boca_app_browser->tab_strip_model()->ActivateTabAt(1);

@@ -28,6 +28,7 @@
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
#include "url/gurl.h" #include "url/gurl.h"
using ::boca::LockedNavigationOptions;
using ::testing::_; using ::testing::_;
using ::testing::StrictMock; using ::testing::StrictMock;
@@ -142,45 +143,47 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest, RegisterUrlsAndRestrictionLevels) {
auto* const on_task_blocklist = window_tracker->on_task_blocklist(); auto* const on_task_blocklist = window_tracker->on_task_blocklist();
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(4), url_a, tab_strip_model->GetWebContentsAt(4), url_a,
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(3), url_b, tab_strip_model->GetWebContentsAt(3), url_b,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(2), url_a_subdomain, tab_strip_model->GetWebContentsAt(2), url_a_subdomain,
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(1), url_b_subdomain, tab_strip_model->GetWebContentsAt(1), url_b_subdomain,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a_subdomain2, tab_strip_model->GetWebContentsAt(0), url_a_subdomain2,
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 5u); ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 5u);
EXPECT_EQ( EXPECT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(4))], tab_strip_model->GetWebContentsAt(4))],
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
EXPECT_EQ( EXPECT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(3))], tab_strip_model->GetWebContentsAt(3))],
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
EXPECT_EQ( EXPECT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(2))], tab_strip_model->GetWebContentsAt(2))],
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
EXPECT_EQ( EXPECT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(1))], tab_strip_model->GetWebContentsAt(1))],
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
EXPECT_EQ( EXPECT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(0))], tab_strip_model->GetWebContentsAt(0))],
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
EXPECT_EQ(on_task_blocklist->one_level_deep_original_url().size(), 2u); EXPECT_EQ(on_task_blocklist->one_level_deep_original_url().size(), 2u);
} }
@@ -201,10 +204,10 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(1), url_a, tab_strip_model->GetWebContentsAt(1), url_a,
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
on_task_blocklist->MaybeSetURLRestrictionLevel( on_task_blocklist->MaybeSetURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a_child, tab_strip_model->GetWebContentsAt(0), url_a_child,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u); ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u);
ASSERT_EQ(on_task_blocklist->child_tab_to_nav_filters().size(), 1u); ASSERT_EQ(on_task_blocklist->child_tab_to_nav_filters().size(), 1u);
@@ -212,12 +215,12 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(1))], tab_strip_model->GetWebContentsAt(1))],
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
EXPECT_EQ( EXPECT_EQ(
on_task_blocklist on_task_blocklist
->child_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->child_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(0))], tab_strip_model->GetWebContentsAt(0))],
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
EXPECT_EQ(on_task_blocklist->one_level_deep_original_url().size(), 1u); EXPECT_EQ(on_task_blocklist->one_level_deep_original_url().size(), 1u);
} }
@@ -239,39 +242,39 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url, tab_strip_model->GetWebContentsAt(0), url,
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(1), url_subdomain, tab_strip_model->GetWebContentsAt(1), url_subdomain,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 2u); ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 2u);
ASSERT_EQ( ASSERT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(0))], tab_strip_model->GetWebContentsAt(0))],
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
on_task_blocklist->MaybeSetURLRestrictionLevel( on_task_blocklist->MaybeSetURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(1), url_subdomain, tab_strip_model->GetWebContentsAt(1), url_subdomain,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
NavigateAndCommitActiveTab(url_subdomain); NavigateAndCommitActiveTab(url_subdomain);
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
NavigateAndCommitActiveTab(url_with_query); NavigateAndCommitActiveTab(url_with_query);
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
NavigateAndCommitActiveTab(url_with_path); NavigateAndCommitActiveTab(url_with_path);
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
} }
TEST_F(OnTaskLockedSessionWindowTrackerTest, NavigateNonParentTab) { TEST_F(OnTaskLockedSessionWindowTrackerTest, NavigateNonParentTab) {
@@ -291,33 +294,33 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest, NavigateNonParentTab) {
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url, tab_strip_model->GetWebContentsAt(0), url,
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
on_task_blocklist->MaybeSetURLRestrictionLevel( on_task_blocklist->MaybeSetURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(1), url_subdomain, tab_strip_model->GetWebContentsAt(1), url_subdomain,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u); ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u);
ASSERT_EQ( ASSERT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(0))], tab_strip_model->GetWebContentsAt(0))],
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
ASSERT_EQ(on_task_blocklist->child_tab_to_nav_filters().size(), 1u); ASSERT_EQ(on_task_blocklist->child_tab_to_nav_filters().size(), 1u);
ASSERT_EQ( ASSERT_EQ(
on_task_blocklist on_task_blocklist
->child_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->child_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(1))], tab_strip_model->GetWebContentsAt(1))],
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(1); EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(1);
browser()->tab_strip_model()->ActivateTabAt(1); browser()->tab_strip_model()->ActivateTabAt(1);
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url),
policy::URLBlocklist::URLBlocklistState::URL_IN_BLOCKLIST); policy::URLBlocklist::URLBlocklistState::URL_IN_BLOCKLIST);
@@ -339,16 +342,16 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url, tab_strip_model->GetWebContentsAt(0), url,
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u); ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u);
ASSERT_EQ( ASSERT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(0))], tab_strip_model->GetWebContentsAt(0))],
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
NavigateAndCommitActiveTab(url_subdomain); NavigateAndCommitActiveTab(url_subdomain);
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
@@ -358,7 +361,7 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
} }
TEST_F(OnTaskLockedSessionWindowTrackerTest, TEST_F(OnTaskLockedSessionWindowTrackerTest,
@@ -376,16 +379,16 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url, tab_strip_model->GetWebContentsAt(0), url,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u); ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u);
ASSERT_EQ( ASSERT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(0))], tab_strip_model->GetWebContentsAt(0))],
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(1); EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(1);
const SessionID active_tab_id = sessions::SessionTabHelper::IdForTab( const SessionID active_tab_id = sessions::SessionTabHelper::IdForTab(
@@ -400,7 +403,7 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
// Sanity check to make sure child tabs aren't added as parent tabs. // Sanity check to make sure child tabs aren't added as parent tabs.
EXPECT_FALSE( EXPECT_FALSE(
on_task_blocklist->IsParentTab(tab_strip_model->GetWebContentsAt(0))); on_task_blocklist->IsParentTab(tab_strip_model->GetWebContentsAt(0)));
@@ -422,17 +425,19 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_subdomain, tab_strip_model->GetWebContentsAt(0), url_subdomain,
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u); ASSERT_EQ(on_task_blocklist->parent_tab_to_nav_filters().size(), 1u);
ASSERT_EQ( ASSERT_EQ(
on_task_blocklist on_task_blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(0))], tab_strip_model->GetWebContentsAt(0))],
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
EXPECT_EQ( EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
on_task_blocklist->current_page_restriction_level(), LockedNavigationOptions::
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
NavigateAndCommitActiveTab(url); NavigateAndCommitActiveTab(url);
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
@@ -441,18 +446,18 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
NavigateAndCommitActiveTab(url_redirect); NavigateAndCommitActiveTab(url_redirect);
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
EXPECT_EQ( EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
on_task_blocklist->current_page_restriction_level(), LockedNavigationOptions::
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
const GURL url_redirect_not_same_domain(kTabUrlRedirectedUrl); const GURL url_redirect_not_same_domain(kTabUrlRedirectedUrl);
NavigateAndCommitActiveTab(url_redirect_not_same_domain); NavigateAndCommitActiveTab(url_redirect_not_same_domain);
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
EXPECT_EQ( EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
on_task_blocklist->current_page_restriction_level(), LockedNavigationOptions::
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(1); EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(1);
const SessionID active_tab_id = sessions::SessionTabHelper::IdForTab( const SessionID active_tab_id = sessions::SessionTabHelper::IdForTab(
tab_strip_model->GetWebContentsAt(0)); tab_strip_model->GetWebContentsAt(0));
@@ -466,7 +471,7 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
browser()->tab_strip_model()->UpdateWebContentsStateAt(0, browser()->tab_strip_model()->UpdateWebContentsStateAt(0,
TabChangeType::kAll); TabChangeType::kAll);
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
} }
TEST_F(OnTaskLockedSessionWindowTrackerTest, SwitchTabWithNewRestrictedLevel) { TEST_F(OnTaskLockedSessionWindowTrackerTest, SwitchTabWithNewRestrictedLevel) {
@@ -486,17 +491,17 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest, SwitchTabWithNewRestrictedLevel) {
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(1), url_a, tab_strip_model->GetWebContentsAt(1), url_a,
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_b, tab_strip_model->GetWebContentsAt(0), url_b,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(1); EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(1);
browser()->tab_strip_model()->ActivateTabAt(1); browser()->tab_strip_model()->ActivateTabAt(1);
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
} }
TEST_F(OnTaskLockedSessionWindowTrackerTest, TEST_F(OnTaskLockedSessionWindowTrackerTest,
@@ -516,11 +521,11 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a),
policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST); policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_b), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_b),
@@ -549,11 +554,11 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a_front_subdomain), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a_front_subdomain),
policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST); policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a_subpage), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a_subpage),
@@ -585,11 +590,11 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a_front_subdomain), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a_front_subdomain),
policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST); policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a_path), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(url_a_path),
@@ -619,11 +624,11 @@ TEST_F(OnTaskLockedSessionWindowTrackerTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), google_url, tab_strip_model->GetWebContentsAt(0), google_url,
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(docs_url), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(docs_url),
policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST); policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST);
EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(random_google_url), EXPECT_EQ(on_task_blocklist->GetURLBlocklistState(random_google_url),
@@ -821,12 +826,12 @@ TEST_F(OnTaskNavigationThrottleTest, AllowUrlSuccessfullyForUnrestrictedNav) {
auto* const on_task_blocklist = window_tracker->on_task_blocklist(); auto* const on_task_blocklist = window_tracker->on_task_blocklist();
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ(on_task_blocklist->current_page_restriction_level(), ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions); LockedNavigationOptions::OPEN_NAVIGATION);
{ {
auto simulator = StartNavigation( auto simulator = StartNavigation(
url_a_front_subdomain, url_a_front_subdomain,
@@ -874,12 +879,12 @@ TEST_F(OnTaskNavigationThrottleTest, BlockUrlSuccessfullyForRestrictedNav) {
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ(on_task_blocklist->current_page_restriction_level(), ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
{ {
auto simulator = StartNavigation( auto simulator = StartNavigation(
url_a_front_subdomain, url_a_front_subdomain,
@@ -929,12 +934,12 @@ TEST_F(OnTaskNavigationThrottleTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ(on_task_blocklist->current_page_restriction_level(), ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
{ {
auto simulator = StartNavigation( auto simulator = StartNavigation(
url_a_front_subdomain, url_a_front_subdomain,
@@ -981,12 +986,12 @@ TEST_F(OnTaskNavigationThrottleTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ(on_task_blocklist->current_page_restriction_level(), ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
ASSERT_TRUE(on_task_blocklist->CanPerformOneLevelNavigation( ASSERT_TRUE(on_task_blocklist->CanPerformOneLevelNavigation(
tab_strip_model->GetWebContentsAt(0))); tab_strip_model->GetWebContentsAt(0)));
auto simulator = StartNavigation( auto simulator = StartNavigation(
@@ -1023,12 +1028,12 @@ TEST_F(OnTaskNavigationThrottleTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ(on_task_blocklist->current_page_restriction_level(), ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
// Add a new tab to the browser to simulate opening a link in a new tab // Add a new tab to the browser to simulate opening a link in a new tab
ASSERT_TRUE(on_task_blocklist->CanPerformOneLevelNavigation( ASSERT_TRUE(on_task_blocklist->CanPerformOneLevelNavigation(
@@ -1059,7 +1064,7 @@ TEST_F(OnTaskNavigationThrottleTest,
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
EXPECT_EQ(on_task_blocklist->current_page_restriction_level(), EXPECT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
// Attempt to navigate on this new page should fail. // Attempt to navigate on this new page should fail.
auto simulator_on_new_page = StartNavigation( auto simulator_on_new_page = StartNavigation(
@@ -1091,13 +1096,14 @@ TEST_F(OnTaskNavigationThrottleTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ( ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
on_task_blocklist->current_page_restriction_level(), LockedNavigationOptions::
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
// Same domain and one level deep works on the current page. // Same domain and one level deep works on the current page.
ASSERT_TRUE(on_task_blocklist->CanPerformOneLevelNavigation( ASSERT_TRUE(on_task_blocklist->CanPerformOneLevelNavigation(
@@ -1148,13 +1154,14 @@ TEST_F(OnTaskNavigationThrottleTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ( ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
on_task_blocklist->current_page_restriction_level(), LockedNavigationOptions::
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
// Add a new tab to the browser to simulate opening a link in a new tab // Add a new tab to the browser to simulate opening a link in a new tab
ASSERT_TRUE(on_task_blocklist->CanPerformOneLevelNavigation( ASSERT_TRUE(on_task_blocklist->CanPerformOneLevelNavigation(
@@ -1220,7 +1227,7 @@ TEST_F(OnTaskNavigationThrottleTest, ClosePopUpIfNotOauth) {
auto* const on_task_blocklist = window_tracker->on_task_blocklist(); auto* const on_task_blocklist = window_tracker->on_task_blocklist();
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
main_browser_tab_strip_model->GetWebContentsAt(0), url_a, main_browser_tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
ASSERT_TRUE(window_tracker->CanOpenNewPopup()); ASSERT_TRUE(window_tracker->CanOpenNewPopup());
const std::unique_ptr<Browser> popup_browser( const std::unique_ptr<Browser> popup_browser(
@@ -1270,7 +1277,7 @@ TEST_F(OnTaskNavigationThrottleTest, OauthPopupAllowed) {
auto* const on_task_blocklist = window_tracker->on_task_blocklist(); auto* const on_task_blocklist = window_tracker->on_task_blocklist();
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
main_browser_tab_strip_model->GetWebContentsAt(0), url_a, main_browser_tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
const std::unique_ptr<Browser> popup_browser( const std::unique_ptr<Browser> popup_browser(
CreateTestBrowser(/*popup=*/true)); CreateTestBrowser(/*popup=*/true));
@@ -1319,7 +1326,7 @@ TEST_F(OnTaskNavigationThrottleTest, SuccessNavigationWorksEvenWithRedirects) {
auto* const on_task_blocklist = window_tracker->on_task_blocklist(); auto* const on_task_blocklist = window_tracker->on_task_blocklist();
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
@@ -1347,7 +1354,7 @@ TEST_F(OnTaskNavigationThrottleTest, BlockUrlInNewTabShouldClose) {
auto* const on_task_blocklist = window_tracker->on_task_blocklist(); auto* const on_task_blocklist = window_tracker->on_task_blocklist();
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(2); EXPECT_CALL(boca_window_observer_, OnActiveTabChanged(_)).Times(2);
@@ -1392,12 +1399,12 @@ TEST_F(OnTaskNavigationThrottleTest, BackForwardReloadNavigationSuccess) {
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ(on_task_blocklist->current_page_restriction_level(), ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
auto simulator = StartNavigation( auto simulator = StartNavigation(
url_a_front_subdomain, url_a_front_subdomain,
tab_strip_model->GetWebContentsAt(0)->GetPrimaryMainFrame()); tab_strip_model->GetWebContentsAt(0)->GetPrimaryMainFrame());
@@ -1457,12 +1464,12 @@ TEST_F(OnTaskNavigationThrottleTest,
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
task_environment()->RunUntilIdle(); task_environment()->RunUntilIdle();
ASSERT_EQ(on_task_blocklist->current_page_restriction_level(), ASSERT_EQ(on_task_blocklist->current_page_restriction_level(),
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
auto simulator = StartNavigation( auto simulator = StartNavigation(
url_a_front_subdomain, url_a_front_subdomain,
tab_strip_model->GetWebContentsAt(0)->GetPrimaryMainFrame()); tab_strip_model->GetWebContentsAt(0)->GetPrimaryMainFrame());
@@ -1526,7 +1533,7 @@ TEST_F(OnTaskNavigationThrottleTest, BlockNavigationForPostMethodRequest) {
auto* const on_task_blocklist = window_tracker->on_task_blocklist(); auto* const on_task_blocklist = window_tracker->on_task_blocklist();
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
tab_strip_model->GetWebContentsAt(0), url_a, tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); LockedNavigationOptions::DOMAIN_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
ASSERT_TRUE(base::test::RunUntil([&window_tracker]() { ASSERT_TRUE(base::test::RunUntil([&window_tracker]() {
return window_tracker->on_task_blocklist()->GetURLBlocklistState( return window_tracker->on_task_blocklist()->GetURLBlocklistState(
@@ -1561,7 +1568,7 @@ TEST_F(OnTaskNavigationThrottleTest,
auto* const on_task_blocklist = window_tracker->on_task_blocklist(); auto* const on_task_blocklist = window_tracker->on_task_blocklist();
on_task_blocklist->SetParentURLRestrictionLevel( on_task_blocklist->SetParentURLRestrictionLevel(
main_browser_tab_strip_model->GetWebContentsAt(0), url_a, main_browser_tab_strip_model->GetWebContentsAt(0), url_a,
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation); LockedNavigationOptions::LIMITED_NAVIGATION);
window_tracker->RefreshUrlBlocklist(); window_tracker->RefreshUrlBlocklist();
// Set OAuth to be in process before firing off another OAuth process within // Set OAuth to be in process before firing off another OAuth process within

@@ -148,7 +148,7 @@ void OnTaskSystemWebAppManagerImpl::SetWindowTrackerForSystemWebAppWindow(
SessionID OnTaskSystemWebAppManagerImpl::CreateBackgroundTabWithUrl( SessionID OnTaskSystemWebAppManagerImpl::CreateBackgroundTabWithUrl(
SessionID window_id, SessionID window_id,
GURL url, GURL url,
OnTaskBlocklist::RestrictionLevel restriction_level) { ::boca::LockedNavigationOptions::NavigationType restriction_level) {
Browser* const browser = GetBrowserWindowWithID(window_id); Browser* const browser = GetBrowserWindowWithID(window_id);
if (!browser) { if (!browser) {
return SessionID::InvalidValue(); return SessionID::InvalidValue();

@@ -41,7 +41,8 @@ class OnTaskSystemWebAppManagerImpl : public OnTaskSystemWebAppManager {
SessionID CreateBackgroundTabWithUrl( SessionID CreateBackgroundTabWithUrl(
SessionID window_id, SessionID window_id,
GURL url, GURL url,
OnTaskBlocklist::RestrictionLevel restriction_level) override; ::boca::LockedNavigationOptions::NavigationType restriction_level)
override;
void RemoveTabsWithTabIds( void RemoveTabsWithTabIds(
SessionID window_id, SessionID window_id,
const std::set<SessionID>& tab_ids_to_remove) override; const std::set<SessionID>& tab_ids_to_remove) override;

@@ -24,6 +24,7 @@
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "url/gurl.h" #include "url/gurl.h"
using ::boca::LockedNavigationOptions;
using ::testing::IsNull; using ::testing::IsNull;
using ::testing::NotNull; using ::testing::NotNull;
using ::testing::Sequence; using ::testing::Sequence;
@@ -179,7 +180,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskSystemWebAppManagerImplBrowserTest,
system_web_app_manager.SetWindowTrackerForTesting(&window_tracker); system_web_app_manager.SetWindowTrackerForTesting(&window_tracker);
system_web_app_manager.CreateBackgroundTabWithUrl( system_web_app_manager.CreateBackgroundTabWithUrl(
boca_app_browser->session_id(), GURL(kTestUrl), boca_app_browser->session_id(), GURL(kTestUrl),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
EXPECT_EQ(boca_app_browser->tab_strip_model()->count(), 2); EXPECT_EQ(boca_app_browser->tab_strip_model()->count(), 2);
content::WebContents* web_contents = content::WebContents* web_contents =
boca_app_browser->tab_strip_model()->GetWebContentsAt(1); boca_app_browser->tab_strip_model()->GetWebContentsAt(1);
@@ -193,7 +194,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskSystemWebAppManagerImplBrowserTest,
blocklist blocklist
->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab( ->parent_tab_to_nav_filters()[sessions::SessionTabHelper::IdForTab(
web_contents)], web_contents)],
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
} }
IN_PROC_BROWSER_TEST_F(OnTaskSystemWebAppManagerImplBrowserTest, IN_PROC_BROWSER_TEST_F(OnTaskSystemWebAppManagerImplBrowserTest,
@@ -223,7 +224,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskSystemWebAppManagerImplBrowserTest,
system_web_app_manager.SetWindowTrackerForTesting(&window_tracker); system_web_app_manager.SetWindowTrackerForTesting(&window_tracker);
const SessionID tab_id = system_web_app_manager.CreateBackgroundTabWithUrl( const SessionID tab_id = system_web_app_manager.CreateBackgroundTabWithUrl(
boca_app_browser->session_id(), GURL(kTestUrl), boca_app_browser->session_id(), GURL(kTestUrl),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
EXPECT_EQ(boca_app_browser->tab_strip_model()->count(), 2); EXPECT_EQ(boca_app_browser->tab_strip_model()->count(), 2);
content::WebContents* const web_contents_1 = content::WebContents* const web_contents_1 =
boca_app_browser->tab_strip_model()->GetWebContentsAt(1); boca_app_browser->tab_strip_model()->GetWebContentsAt(1);
@@ -263,7 +264,7 @@ IN_PROC_BROWSER_TEST_F(OnTaskSystemWebAppManagerImplBrowserTest,
// Create tab so we can verify it gets cleaned up with window prep. // Create tab so we can verify it gets cleaned up with window prep.
system_web_app_manager.CreateBackgroundTabWithUrl( system_web_app_manager.CreateBackgroundTabWithUrl(
boca_app_browser->session_id(), GURL(kTestUrl), boca_app_browser->session_id(), GURL(kTestUrl),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); LockedNavigationOptions::BLOCK_NAVIGATION);
ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2); ASSERT_EQ(boca_app_browser->tab_strip_model()->count(), 2);
// Verify that the tab is cleaned up after window prep. // Verify that the tab is cleaned up after window prep.

@@ -18,6 +18,9 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
namespace { namespace {
using ::boca::LockedNavigationOptions;
constexpr char kAllTrafficWildcard[] = "*"; constexpr char kAllTrafficWildcard[] = "*";
const std::string& GetCommonUrlPrefix() { const std::string& GetCommonUrlPrefix() {
@@ -69,7 +72,7 @@ OnTaskBlocklist::~OnTaskBlocklist() {
policy::URLBlocklist::URLBlocklistState OnTaskBlocklist::GetURLBlocklistState( policy::URLBlocklist::URLBlocklistState OnTaskBlocklist::GetURLBlocklistState(
const GURL& url) const { const GURL& url) const {
if (current_page_restriction_level_ == if (current_page_restriction_level_ ==
OnTaskBlocklist::RestrictionLevel::kNoRestrictions) { LockedNavigationOptions::OPEN_NAVIGATION) {
return policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST; return policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST;
} }
@@ -95,7 +98,7 @@ policy::URLBlocklist::URLBlocklistState OnTaskBlocklist::GetURLBlocklistState(
if (previous_url_.is_valid() && if (previous_url_.is_valid() &&
current_page_restriction_level_ == current_page_restriction_level_ ==
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation) { LockedNavigationOptions::BLOCK_NAVIGATION) {
return previous_url_ == url return previous_url_ == url
? policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST ? policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST
: policy::URLBlocklist::URLBlocklistState::URL_IN_BLOCKLIST; : policy::URLBlocklist::URLBlocklistState::URL_IN_BLOCKLIST;
@@ -104,17 +107,17 @@ policy::URLBlocklist::URLBlocklistState OnTaskBlocklist::GetURLBlocklistState(
} }
bool OnTaskBlocklist::IsCurrentRestrictionOneLevelDeep() { bool OnTaskBlocklist::IsCurrentRestrictionOneLevelDeep() {
return ( return (current_page_restriction_level_ ==
current_page_restriction_level_ == LockedNavigationOptions::LIMITED_NAVIGATION ||
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation || current_page_restriction_level_ ==
current_page_restriction_level_ == LockedNavigationOptions::
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation); SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION);
} }
bool OnTaskBlocklist::MaybeSetURLRestrictionLevel( bool OnTaskBlocklist::MaybeSetURLRestrictionLevel(
content::WebContents* tab, content::WebContents* tab,
const GURL& url, const GURL& url,
OnTaskBlocklist::RestrictionLevel restriction_level) { LockedNavigationOptions::NavigationType restriction_level) {
const SessionID tab_id = sessions::SessionTabHelper::IdForTab(tab); const SessionID tab_id = sessions::SessionTabHelper::IdForTab(tab);
if (!tab_id.is_valid()) { if (!tab_id.is_valid()) {
return false; return false;
@@ -127,10 +130,10 @@ bool OnTaskBlocklist::MaybeSetURLRestrictionLevel(
} else { } else {
child_tab_to_nav_filters_[tab_id] = restriction_level; child_tab_to_nav_filters_[tab_id] = restriction_level;
} }
if (restriction_level == if (restriction_level == LockedNavigationOptions::LIMITED_NAVIGATION ||
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation ||
restriction_level == restriction_level ==
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation) { LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION) {
one_level_deep_original_url_[tab_id] = url; one_level_deep_original_url_[tab_id] = url;
} }
return true; return true;
@@ -139,16 +142,16 @@ bool OnTaskBlocklist::MaybeSetURLRestrictionLevel(
void OnTaskBlocklist::SetParentURLRestrictionLevel( void OnTaskBlocklist::SetParentURLRestrictionLevel(
content::WebContents* tab, content::WebContents* tab,
const GURL& url, const GURL& url,
OnTaskBlocklist::RestrictionLevel restriction_level) { LockedNavigationOptions::NavigationType restriction_level) {
const SessionID tab_id = sessions::SessionTabHelper::IdForTab(tab); const SessionID tab_id = sessions::SessionTabHelper::IdForTab(tab);
if (!tab_id.is_valid()) { if (!tab_id.is_valid()) {
return; return;
} }
parent_tab_to_nav_filters_[tab_id] = restriction_level; parent_tab_to_nav_filters_[tab_id] = restriction_level;
if (restriction_level == if (restriction_level == LockedNavigationOptions::LIMITED_NAVIGATION ||
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation ||
restriction_level == restriction_level ==
OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation) { LockedNavigationOptions::
SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION) {
one_level_deep_original_url_[tab_id] = url; one_level_deep_original_url_[tab_id] = url;
} }
} }
@@ -169,7 +172,7 @@ void OnTaskBlocklist::RefreshForUrlBlocklist(content::WebContents* tab) {
} }
std::unique_ptr<OnTaskBlocklistSource> blocklist_source; std::unique_ptr<OnTaskBlocklistSource> blocklist_source;
OnTaskBlocklist::RestrictionLevel restriction_level; LockedNavigationOptions::NavigationType restriction_level;
// Updates the blocklist given the active tab's url. This function does a // Updates the blocklist given the active tab's url. This function does a
// series of checks to determine what restriction levels apply. It starts at // series of checks to determine what restriction levels apply. It starts at
// closest match starting from the child maps and continues outwards to least // closest match starting from the child maps and continues outwards to least
@@ -191,19 +194,19 @@ void OnTaskBlocklist::RefreshForUrlBlocklist(content::WebContents* tab) {
} else { } else {
// Should only happen if a url redirect opens in a new tab. // Should only happen if a url redirect opens in a new tab.
if (current_page_restriction_level_ == if (current_page_restriction_level_ ==
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation) { LockedNavigationOptions::LIMITED_NAVIGATION) {
blocklist_source = std::make_unique<OnTaskBlocklistSource>( blocklist_source = std::make_unique<OnTaskBlocklistSource>(
url, OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); url, LockedNavigationOptions::BLOCK_NAVIGATION);
current_page_restriction_level_ = current_page_restriction_level_ =
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation; LockedNavigationOptions::BLOCK_NAVIGATION;
} else if (current_page_restriction_level_ == } else if (current_page_restriction_level_ ==
OnTaskBlocklist::RestrictionLevel:: LockedNavigationOptions::
kDomainAndOneLevelDeepNavigation) { SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION) {
if (!url.DomainIs(previous_url_.GetWithEmptyPath().GetContentPiece())) { if (!url.DomainIs(previous_url_.GetWithEmptyPath().GetContentPiece())) {
blocklist_source = std::make_unique<OnTaskBlocklistSource>( blocklist_source = std::make_unique<OnTaskBlocklistSource>(
url, OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); url, LockedNavigationOptions::DOMAIN_NAVIGATION);
current_page_restriction_level_ = current_page_restriction_level_ =
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation; LockedNavigationOptions::BLOCK_NAVIGATION;
} }
} else { } else {
blocklist_source = std::make_unique<OnTaskBlocklistSource>( blocklist_source = std::make_unique<OnTaskBlocklistSource>(
@@ -261,12 +264,12 @@ const policy::URLBlocklistManager* OnTaskBlocklist::url_blocklist_manager() {
return url_blocklist_manager_.get(); return url_blocklist_manager_.get();
} }
std::map<SessionID, OnTaskBlocklist::RestrictionLevel> std::map<SessionID, LockedNavigationOptions::NavigationType>
OnTaskBlocklist::parent_tab_to_nav_filters() { OnTaskBlocklist::parent_tab_to_nav_filters() {
return parent_tab_to_nav_filters_; return parent_tab_to_nav_filters_;
} }
std::map<SessionID, OnTaskBlocklist::RestrictionLevel> std::map<SessionID, LockedNavigationOptions::NavigationType>
OnTaskBlocklist::child_tab_to_nav_filters() { OnTaskBlocklist::child_tab_to_nav_filters() {
return child_tab_to_nav_filters_; return child_tab_to_nav_filters_;
} }
@@ -275,7 +278,7 @@ std::map<SessionID, GURL> OnTaskBlocklist::one_level_deep_original_url() {
return one_level_deep_original_url_; return one_level_deep_original_url_;
} }
OnTaskBlocklist::RestrictionLevel LockedNavigationOptions::NavigationType
OnTaskBlocklist::current_page_restriction_level() { OnTaskBlocklist::current_page_restriction_level() {
return current_page_restriction_level_; return current_page_restriction_level_;
} }
@@ -298,18 +301,24 @@ void OnTaskBlocklist::CleanupBlocklist() {
// OnTaskBlock::BlocklistSource Implementation // OnTaskBlock::BlocklistSource Implementation
OnTaskBlocklist::OnTaskBlocklistSource::OnTaskBlocklistSource( OnTaskBlocklist::OnTaskBlocklistSource::OnTaskBlocklistSource(
const GURL& url, const GURL& url,
OnTaskBlocklist::RestrictionLevel restriction_type) { LockedNavigationOptions::NavigationType restriction_type) {
switch (restriction_type) { switch (restriction_type) {
case OnTaskBlocklist::RestrictionLevel::kDomainAndOneLevelDeepNavigation: case LockedNavigationOptions::
case OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation: SAME_DOMAIN_OPEN_OTHER_DOMAIN_LIMITED_NAVIGATION:
case OnTaskBlocklist::RestrictionLevel::kNoRestrictions: case LockedNavigationOptions::LIMITED_NAVIGATION:
case LockedNavigationOptions::OPEN_NAVIGATION:
allowlist_ = GetAllTrafficFilter(); allowlist_ = GetAllTrafficFilter();
return; return;
case OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation: case LockedNavigationOptions::DOMAIN_NAVIGATION:
blocklist_ = GetAllTrafficFilter(); blocklist_ = GetAllTrafficFilter();
allowlist_ = GetDomainLevelTrafficFilter(url); allowlist_ = GetDomainLevelTrafficFilter(url);
return; return;
case OnTaskBlocklist::RestrictionLevel::kLimitedNavigation: case LockedNavigationOptions::NAVIGATION_TYPE_UNKNOWN:
case LockedNavigationOptions::BLOCK_NAVIGATION:
blocklist_ = GetAllTrafficFilter();
allowlist_ = GetLimitedTrafficFilter(url);
return;
default:
blocklist_ = GetAllTrafficFilter(); blocklist_ = GetAllTrafficFilter();
allowlist_ = GetLimitedTrafficFilter(url); allowlist_ = GetLimitedTrafficFilter(url);
return; return;

@@ -10,6 +10,7 @@
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chromeos/ash/components/boca/proto/bundle.pb.h"
#include "components/policy/core/browser/url_blocklist_manager.h" #include "components/policy/core/browser/url_blocklist_manager.h"
#include "components/sessions/core/session_id.h" #include "components/sessions/core/session_id.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
@@ -19,15 +20,6 @@
// restrictions for each tab. // restrictions for each tab.
class OnTaskBlocklist { class OnTaskBlocklist {
public: public:
enum class RestrictionLevel {
kNoRestrictions = 1, // No url restrictions.
kLimitedNavigation, // Only allow exact URL match.
kSameDomainNavigation, // Allow domain/subdomain navigation.
kOneLevelDeepNavigation, // Allow one level deeper navigation.
kDomainAndOneLevelDeepNavigation, // Allows same domain traversal and one
// level deep.
};
// BlocklistSource implementation that blocks all traffic with the // BlocklistSource implementation that blocks all traffic with the
// exception of URLs specified by the teacher's navigation restriction level. // exception of URLs specified by the teacher's navigation restriction level.
// Note that this implementation only supports one observer at a time. Adding // Note that this implementation only supports one observer at a time. Adding
@@ -35,8 +27,9 @@ class OnTaskBlocklist {
// from the main thread. // from the main thread.
class OnTaskBlocklistSource : public policy::BlocklistSource { class OnTaskBlocklistSource : public policy::BlocklistSource {
public: public:
OnTaskBlocklistSource(const GURL& url, OnTaskBlocklistSource(
OnTaskBlocklist::RestrictionLevel restriction_type); const GURL& url,
::boca::LockedNavigationOptions::NavigationType restriction_type);
OnTaskBlocklistSource(const OnTaskBlocklistSource&) = delete; OnTaskBlocklistSource(const OnTaskBlocklistSource&) = delete;
OnTaskBlocklistSource& operator=(const OnTaskBlocklistSource&) = delete; OnTaskBlocklistSource& operator=(const OnTaskBlocklistSource&) = delete;
~OnTaskBlocklistSource() override = default; ~OnTaskBlocklistSource() override = default;
@@ -68,14 +61,14 @@ class OnTaskBlocklist {
bool MaybeSetURLRestrictionLevel( bool MaybeSetURLRestrictionLevel(
content::WebContents* tab, content::WebContents* tab,
const GURL& url, const GURL& url,
OnTaskBlocklist::RestrictionLevel restriction_level); ::boca::LockedNavigationOptions::NavigationType restriction_level);
// Sets the url restrictions for the given `url` with `restriction_level`. // Sets the url restrictions for the given `url` with `restriction_level`.
// Should only be called for the set of urls sent by the boca producer. // Should only be called for the set of urls sent by the boca producer.
void SetParentURLRestrictionLevel( void SetParentURLRestrictionLevel(
content::WebContents* tab, content::WebContents* tab,
const GURL& url, const GURL& url,
OnTaskBlocklist::RestrictionLevel restriction_level); ::boca::LockedNavigationOptions::NavigationType restriction_level);
// Updates the blocklist that is associated with the given `tab`. This is // Updates the blocklist that is associated with the given `tab`. This is
// triggered on an active tab change or when the current tab changes. // triggered on an active tab change or when the current tab changes.
@@ -107,22 +100,24 @@ class OnTaskBlocklist {
content::WebContents* previous_tab(); content::WebContents* previous_tab();
const policy::URLBlocklistManager* url_blocklist_manager(); const policy::URLBlocklistManager* url_blocklist_manager();
std::map<SessionID, OnTaskBlocklist::RestrictionLevel> std::map<SessionID, ::boca::LockedNavigationOptions::NavigationType>
parent_tab_to_nav_filters(); parent_tab_to_nav_filters();
std::map<SessionID, OnTaskBlocklist::RestrictionLevel> std::map<SessionID, ::boca::LockedNavigationOptions::NavigationType>
child_tab_to_nav_filters(); child_tab_to_nav_filters();
std::map<SessionID, GURL> one_level_deep_original_url(); std::map<SessionID, GURL> one_level_deep_original_url();
OnTaskBlocklist::RestrictionLevel current_page_restriction_level(); ::boca::LockedNavigationOptions::NavigationType
current_page_restriction_level();
private: private:
OnTaskBlocklist::RestrictionLevel current_page_restriction_level_ = ::boca::LockedNavigationOptions::NavigationType
OnTaskBlocklist::RestrictionLevel::kNoRestrictions; current_page_restriction_level_ =
::boca::LockedNavigationOptions::OPEN_NAVIGATION;
base::WeakPtr<content::WebContents> previous_tab_; base::WeakPtr<content::WebContents> previous_tab_;
GURL previous_url_; GURL previous_url_;
bool first_time_popup_ = true; bool first_time_popup_ = true;
std::map<SessionID, OnTaskBlocklist::RestrictionLevel> std::map<SessionID, ::boca::LockedNavigationOptions::NavigationType>
parent_tab_to_nav_filters_; parent_tab_to_nav_filters_;
std::map<SessionID, OnTaskBlocklist::RestrictionLevel> std::map<SessionID, ::boca::LockedNavigationOptions::NavigationType>
child_tab_to_nav_filters_; child_tab_to_nav_filters_;
std::map<SessionID, GURL> one_level_deep_original_url_; std::map<SessionID, GURL> one_level_deep_original_url_;
const std::unique_ptr<policy::URLBlocklistManager> url_blocklist_manager_; const std::unique_ptr<policy::URLBlocklistManager> url_blocklist_manager_;

@@ -33,22 +33,6 @@ constexpr base::TimeDelta kRemoveTabRetryDelay = base::Seconds(3);
// Delay in seconds before we attempt to pin or unpin the active SWA window. // Delay in seconds before we attempt to pin or unpin the active SWA window.
constexpr base::TimeDelta kSetPinnedStateDelay = base::Seconds(3); constexpr base::TimeDelta kSetPinnedStateDelay = base::Seconds(3);
OnTaskBlocklist::RestrictionLevel NavigationTypeToRestrictionLevel(
::boca::LockedNavigationOptions::NavigationType navigation_type) {
switch (navigation_type) {
case ::boca::LockedNavigationOptions::OPEN_NAVIGATION:
return OnTaskBlocklist::RestrictionLevel::kNoRestrictions;
case ::boca::LockedNavigationOptions::BLOCK_NAVIGATION:
return OnTaskBlocklist::RestrictionLevel::kLimitedNavigation;
case ::boca::LockedNavigationOptions::DOMAIN_NAVIGATION:
return OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation;
case ::boca::LockedNavigationOptions::LIMITED_NAVIGATION:
return OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation;
default:
return OnTaskBlocklist::RestrictionLevel::kNoRestrictions;
}
}
} // namespace } // namespace
OnTaskSessionManager::OnTaskSessionManager( OnTaskSessionManager::OnTaskSessionManager(
@@ -118,13 +102,13 @@ void OnTaskSessionManager::OnBundleUpdated(const ::boca::Bundle& bundle) {
const GURL url(content_config.url()); const GURL url(content_config.url());
current_urls_set.insert(url); current_urls_set.insert(url);
OnTaskBlocklist::RestrictionLevel restriction_level; ::boca::LockedNavigationOptions::NavigationType restriction_level;
if (content_config.has_locked_navigation_options()) { if (content_config.has_locked_navigation_options()) {
::boca::LockedNavigationOptions_NavigationType navigation_type = ::boca::LockedNavigationOptions_NavigationType navigation_type =
content_config.locked_navigation_options().navigation_type(); content_config.locked_navigation_options().navigation_type();
restriction_level = NavigationTypeToRestrictionLevel(navigation_type); restriction_level = navigation_type;
} else { } else {
restriction_level = OnTaskBlocklist::RestrictionLevel::kNoRestrictions; restriction_level = ::boca::LockedNavigationOptions::OPEN_NAVIGATION;
} }
// No need to add the tab if the tab is already tracked as opened in the // No need to add the tab if the tab is already tracked as opened in the
@@ -187,8 +171,9 @@ void OnTaskSessionManager::OnAppReloaded() {
// clear stale tab ids that were tracked with the previous instance. // clear stale tab ids that were tracked with the previous instance.
for (auto& [provider_sent_url, tab_ids] : provider_url_tab_ids_map_) { for (auto& [provider_sent_url, tab_ids] : provider_url_tab_ids_map_) {
tab_ids.clear(); tab_ids.clear();
OnTaskBlocklist::RestrictionLevel restriction_level = OnTaskBlocklist:: ::boca::LockedNavigationOptions::NavigationType restriction_level =
RestrictionLevel::kSameDomainNavigation; // Default restriction. ::boca::LockedNavigationOptions::DOMAIN_NAVIGATION; // Default
// restriction.
if (provider_url_restriction_level_map_.contains(provider_sent_url)) { if (provider_url_restriction_level_map_.contains(provider_sent_url)) {
restriction_level = restriction_level =
provider_url_restriction_level_map_[provider_sent_url]; provider_url_restriction_level_map_[provider_sent_url];
@@ -253,7 +238,7 @@ void OnTaskSessionManager::SystemWebAppLaunchHelper::LaunchBocaSWA() {
void OnTaskSessionManager::SystemWebAppLaunchHelper::AddTab( void OnTaskSessionManager::SystemWebAppLaunchHelper::AddTab(
GURL url, GURL url,
OnTaskBlocklist::RestrictionLevel restriction_level, ::boca::LockedNavigationOptions::NavigationType restriction_level,
base::OnceCallback<void(SessionID)> callback) { base::OnceCallback<void(SessionID)> callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (launch_in_progress_) { if (launch_in_progress_) {
@@ -339,7 +324,7 @@ void OnTaskSessionManager::SystemWebAppLaunchHelper::OnBocaSWALaunched(
void OnTaskSessionManager::OnBundleTabAdded( void OnTaskSessionManager::OnBundleTabAdded(
GURL url, GURL url,
OnTaskBlocklist::RestrictionLevel restriction_level, ::boca::LockedNavigationOptions::NavigationType restriction_level,
SessionID tab_id) { SessionID tab_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (tab_id.is_valid()) { if (tab_id.is_valid()) {

@@ -69,9 +69,10 @@ class OnTaskSessionManager : public boca::BocaSessionManager::Observer,
~SystemWebAppLaunchHelper(); ~SystemWebAppLaunchHelper();
void LaunchBocaSWA(); void LaunchBocaSWA();
void AddTab(GURL url, void AddTab(
OnTaskBlocklist::RestrictionLevel restriction_level, GURL url,
base::OnceCallback<void(SessionID)> callback); ::boca::LockedNavigationOptions::NavigationType restriction_level,
base::OnceCallback<void(SessionID)> callback);
void RemoveTab(const std::set<SessionID>& tab_ids_to_remove, void RemoveTab(const std::set<SessionID>& tab_ids_to_remove,
base::OnceClosure callback); base::OnceClosure callback);
void SetPinStateForActiveSWAWindow(bool pinned, base::OnceClosure callback); void SetPinStateForActiveSWAWindow(bool pinned, base::OnceClosure callback);
@@ -94,9 +95,10 @@ class OnTaskSessionManager : public boca::BocaSessionManager::Observer,
}; };
// Callback triggered when a tab from the bundle is added. // Callback triggered when a tab from the bundle is added.
void OnBundleTabAdded(GURL url, void OnBundleTabAdded(
OnTaskBlocklist::RestrictionLevel restriction_level, GURL url,
SessionID tab_id); ::boca::LockedNavigationOptions::NavigationType restriction_level,
SessionID tab_id);
// Callback triggered when a tab from the bundle is removed. // Callback triggered when a tab from the bundle is removed.
void OnBundleTabRemoved(GURL url); void OnBundleTabRemoved(GURL url);
@@ -117,7 +119,7 @@ class OnTaskSessionManager : public boca::BocaSessionManager::Observer,
// Maps the url that providers send to the restriction levels it is currently // Maps the url that providers send to the restriction levels it is currently
// set to. This map allows for tracking restriction level updates. // set to. This map allows for tracking restriction level updates.
base::flat_map<GURL, OnTaskBlocklist::RestrictionLevel> base::flat_map<GURL, ::boca::LockedNavigationOptions::NavigationType>
provider_url_restriction_level_map_ GUARDED_BY_CONTEXT(sequence_checker_); provider_url_restriction_level_map_ GUARDED_BY_CONTEXT(sequence_checker_);
const std::unique_ptr<OnTaskExtensionsManager> extensions_manager_; const std::unique_ptr<OnTaskExtensionsManager> extensions_manager_;

@@ -58,12 +58,13 @@ class OnTaskSystemWebAppManagerMock : public OnTaskSystemWebAppManager {
(SessionID window_id, (SessionID window_id,
const std::vector<boca::BocaWindowObserver*> observers), const std::vector<boca::BocaWindowObserver*> observers),
(override)); (override));
MOCK_METHOD(SessionID, MOCK_METHOD(
CreateBackgroundTabWithUrl, SessionID,
(SessionID window_id, CreateBackgroundTabWithUrl,
GURL url, (SessionID window_id,
OnTaskBlocklist::RestrictionLevel restriction_level), GURL url,
(override)); ::boca::LockedNavigationOptions::NavigationType restriction_level),
(override));
MOCK_METHOD(void, MOCK_METHOD(void,
RemoveTabsWithTabIds, RemoveTabsWithTabIds,
(SessionID window_id, (SessionID window_id,
@@ -105,7 +106,7 @@ class OnTaskSessionManagerTest : public ::testing::Test {
return &session_manager_->provider_url_tab_ids_map_; return &session_manager_->provider_url_tab_ids_map_;
} }
base::flat_map<GURL, OnTaskBlocklist::RestrictionLevel>* base::flat_map<GURL, ::boca::LockedNavigationOptions::NavigationType>*
provider_url_restriction_level_map() { provider_url_restriction_level_map() {
DCHECK_CALLED_ON_VALID_SEQUENCE(session_manager_->sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(session_manager_->sequence_checker_);
return &session_manager_->provider_url_restriction_level_map_; return &session_manager_->provider_url_restriction_level_map_;
@@ -256,27 +257,27 @@ TEST_F(OnTaskSessionManagerTest, ShouldApplyRestrictionsToTabsOnBundleUpdated) {
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl1), kWindowId, GURL(kTestUrl1),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions)) ::boca::LockedNavigationOptions::OPEN_NAVIGATION))
.WillOnce(Return(kTabId_1)); .WillOnce(Return(kTabId_1));
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl2), kWindowId, GURL(kTestUrl2),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation)) ::boca::LockedNavigationOptions::BLOCK_NAVIGATION))
.WillOnce(Return(kTabId_2)); .WillOnce(Return(kTabId_2));
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl3), kWindowId, GURL(kTestUrl3),
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation)) ::boca::LockedNavigationOptions::DOMAIN_NAVIGATION))
.WillOnce(Return(kTabId_3)); .WillOnce(Return(kTabId_3));
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl4), kWindowId, GURL(kTestUrl4),
OnTaskBlocklist::RestrictionLevel::kOneLevelDeepNavigation)) ::boca::LockedNavigationOptions::LIMITED_NAVIGATION))
.WillOnce(Return(kTabId_4)); .WillOnce(Return(kTabId_4));
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl5), kWindowId, GURL(kTestUrl5),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions)) ::boca::LockedNavigationOptions::OPEN_NAVIGATION))
.WillOnce(Return(kTabId_5)); .WillOnce(Return(kTabId_5));
::boca::Bundle bundle; ::boca::Bundle bundle;
@@ -491,7 +492,7 @@ TEST_F(OnTaskSessionManagerTest, ShouldUpdateRestrictionsToTabOnBundleUpdated) {
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl1), kWindowId, GURL(kTestUrl1),
OnTaskBlocklist::RestrictionLevel::kNoRestrictions)) ::boca::LockedNavigationOptions::OPEN_NAVIGATION))
.WillOnce(Return(kTabId_1)); .WillOnce(Return(kTabId_1));
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
RemoveTabsWithTabIds(kWindowId, std::set<SessionID>{kTabId_1})) RemoveTabsWithTabIds(kWindowId, std::set<SessionID>{kTabId_1}))
@@ -500,7 +501,7 @@ TEST_F(OnTaskSessionManagerTest, ShouldUpdateRestrictionsToTabOnBundleUpdated) {
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl1), kWindowId, GURL(kTestUrl1),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation)) ::boca::LockedNavigationOptions::BLOCK_NAVIGATION))
.InSequence(s) .InSequence(s)
.WillOnce(Return(kTabId_1)); .WillOnce(Return(kTabId_1));
::boca::Bundle bundle; ::boca::Bundle bundle;
@@ -532,13 +533,13 @@ TEST_F(OnTaskSessionManagerTest, OnAppReloadWithNoActiveWindow) {
TEST_F(OnTaskSessionManagerTest, RestoreTabsOnAppReload) { TEST_F(OnTaskSessionManagerTest, RestoreTabsOnAppReload) {
// Inject tab ids and nav restrictions tracked by the previous session for // Inject tab ids and nav restrictions tracked by the previous session for
// testing purposes. It should fall back to // testing purposes. It should fall back to
// `OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation` if there is no // `::boca::LockedNavigationOptions::DOMAIN_NAVIGATION` if
// nav restriction being tracked. // there is no nav restriction being tracked.
const SessionID kOldTabId1 = SessionID::NewUnique(); const SessionID kOldTabId1 = SessionID::NewUnique();
const SessionID kOldTabId2 = SessionID::NewUnique(); const SessionID kOldTabId2 = SessionID::NewUnique();
(*provider_url_tab_ids_map())[GURL(kTestUrl1)].insert(kOldTabId1); (*provider_url_tab_ids_map())[GURL(kTestUrl1)].insert(kOldTabId1);
(*provider_url_restriction_level_map())[GURL(kTestUrl1)] = (*provider_url_restriction_level_map())[GURL(kTestUrl1)] =
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation; ::boca::LockedNavigationOptions::BLOCK_NAVIGATION;
(*provider_url_tab_ids_map())[GURL(kTestUrl2)].insert(kOldTabId2); (*provider_url_tab_ids_map())[GURL(kTestUrl2)].insert(kOldTabId2);
// Attempt an app reload and verify tabs are restored with newer tab ids. // Attempt an app reload and verify tabs are restored with newer tab ids.
@@ -562,13 +563,13 @@ TEST_F(OnTaskSessionManagerTest, RestoreTabsOnAppReload) {
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl1), kWindowId, GURL(kTestUrl1),
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation)) ::boca::LockedNavigationOptions::BLOCK_NAVIGATION))
.InSequence(s) .InSequence(s)
.WillOnce(Return(kTabId1)); .WillOnce(Return(kTabId1));
EXPECT_CALL(*system_web_app_manager_ptr_, EXPECT_CALL(*system_web_app_manager_ptr_,
CreateBackgroundTabWithUrl( CreateBackgroundTabWithUrl(
kWindowId, GURL(kTestUrl2), kWindowId, GURL(kTestUrl2),
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation)) ::boca::LockedNavigationOptions::DOMAIN_NAVIGATION))
.InSequence(s) .InSequence(s)
.WillOnce(Return(kTabId2)); .WillOnce(Return(kTabId2));
session_manager_->OnAppReloaded(); session_manager_->OnAppReloaded();
@@ -577,11 +578,11 @@ TEST_F(OnTaskSessionManagerTest, RestoreTabsOnAppReload) {
EXPECT_THAT((*provider_url_tab_ids_map())[GURL(kTestUrl1)], EXPECT_THAT((*provider_url_tab_ids_map())[GURL(kTestUrl1)],
ElementsAre(kTabId1)); ElementsAre(kTabId1));
EXPECT_EQ((*provider_url_restriction_level_map())[GURL(kTestUrl1)], EXPECT_EQ((*provider_url_restriction_level_map())[GURL(kTestUrl1)],
OnTaskBlocklist::RestrictionLevel::kLimitedNavigation); ::boca::LockedNavigationOptions::BLOCK_NAVIGATION);
EXPECT_THAT((*provider_url_tab_ids_map())[GURL(kTestUrl2)], EXPECT_THAT((*provider_url_tab_ids_map())[GURL(kTestUrl2)],
ElementsAre(kTabId2)); ElementsAre(kTabId2));
EXPECT_EQ((*provider_url_restriction_level_map())[GURL(kTestUrl2)], EXPECT_EQ((*provider_url_restriction_level_map())[GURL(kTestUrl2)],
OnTaskBlocklist::RestrictionLevel::kSameDomainNavigation); ::boca::LockedNavigationOptions::DOMAIN_NAVIGATION);
} }
TEST_F(OnTaskSessionManagerTest, TEST_F(OnTaskSessionManagerTest,

@@ -49,7 +49,7 @@ class OnTaskSystemWebAppManager {
virtual SessionID CreateBackgroundTabWithUrl( virtual SessionID CreateBackgroundTabWithUrl(
SessionID window_id, SessionID window_id,
GURL url, GURL url,
OnTaskBlocklist::RestrictionLevel restriction_level) = 0; ::boca::LockedNavigationOptions::NavigationType restriction_level) = 0;
// Removes tabs with the given tab ids in the specified Boca SWA window. // Removes tabs with the given tab ids in the specified Boca SWA window.
virtual void RemoveTabsWithTabIds( virtual void RemoveTabsWithTabIds(