File: on_task_session_manager_browsertest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (924 lines) | stat: -rw-r--r-- 40,345 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/boca/on_task/on_task_session_manager.h"

#include "ash/constants/ash_features.h"
#include "ash/webui/boca_ui/url_constants.h"
#include "ash/webui/system_apps/public/system_web_app_type.h"
#include "base/test/run_until.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "chrome/browser/ash/boca/boca_manager.h"
#include "chrome/browser/ash/boca/boca_manager_factory.h"
#include "chrome/browser/ash/system_web_apps/system_web_app_manager.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/ash/system_web_apps/system_web_app_ui_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chromeos/ash/components/boca/on_task/notification_constants.h"
#include "chromeos/ash/components/boca/on_task/on_task_notifications_manager.h"
#include "chromeos/ash/components/boca/on_task/util/mock_clock.h"
#include "chromeos/ui/wm/window_util.h"
#include "components/sessions/core/session_id.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "content/public/test/navigation_handle_observer.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gmock/include/gmock/gmock.h"

using ::boca::LockedNavigationOptions;
using ::testing::IsNull;
using ::testing::NotNull;

namespace ash::boca {
namespace {

constexpr char kSessionId[] = "test_session_id";
constexpr char kSessionId2[] = "test_session_id_2";
constexpr char kTestUrl1[] = "https://test1.com";
constexpr char kTestUrl2[] = "https://test2.com";

// Fake delegate implementation for the `OnTaskNotificationsManager` to minimize
// dependency on Ash UI.
class FakeOnTaskNotificationsManagerDelegate
    : public boca::OnTaskNotificationsManager::Delegate {
 public:
  FakeOnTaskNotificationsManagerDelegate() = default;
  ~FakeOnTaskNotificationsManagerDelegate() override = default;

  // OnTaskNotificationsManager::Delegate:
  void ShowNotification(
      std::unique_ptr<message_center::Notification> notification) override {
    notifications_shown_.insert(notification->id());
  }
  void ClearNotification(const std::string& notification_id) override {
    notifications_shown_.erase(notification_id);
  }

  bool WasNotificationShown(const std::string& id) {
    return notifications_shown_.contains(id);
  }

 private:
  std::set<std::string> notifications_shown_;
};

class OnTaskSessionManagerBrowserTestBase : public InProcessBrowserTest {
 protected:
  OnTaskSessionManagerBrowserTestBase() {
    // Initialize the MockClock.
    boca::MockClock::Get();
  }

  void SetUpOnMainThread() override {
    ash::SystemWebAppManager::Get(profile())->InstallSystemAppsForTesting();
    host_resolver()->AddRule("*", "127.0.0.1");
    mock_cert_verifier_.mock_cert_verifier()->set_default_result(net::OK);
    https_server()->AddDefaultHandlers(
        InProcessBrowserTest::GetChromeTestDataDir());

    // Override notification manager implementation to minimize dependency on
    // Ash UI.
    auto fake_notifications_delegate =
        std::make_unique<FakeOnTaskNotificationsManagerDelegate>();
    fake_notifications_delegate_ptr_ = fake_notifications_delegate.get();
    GetOnTaskSessionManager()->SetNotificationManagerForTesting(
        boca::OnTaskNotificationsManager::CreateForTest(
            std::move(fake_notifications_delegate)));

    InProcessBrowserTest::SetUpOnMainThread();
  }

  void TearDownOnMainThread() override {
    fake_notifications_delegate_ptr_ = nullptr;
    InProcessBrowserTest::TearDownOnMainThread();
  }

  void SetUpCommandLine(base::CommandLine* command_line) override {
    mock_cert_verifier_.SetUpCommandLine(command_line);
  }

  void SetUpInProcessBrowserTestFixture() override {
    mock_cert_verifier_.SetUpInProcessBrowserTestFixture();
    ASSERT_TRUE(embedded_test_server()->Start());
  }

  void TearDownInProcessBrowserTestFixture() override {
    mock_cert_verifier_.TearDownInProcessBrowserTestFixture();
  }

  OnTaskSessionManager* GetOnTaskSessionManager() {
    ash::BocaManager* const boca_manager =
        ash::BocaManagerFactory::GetInstance()->GetForProfile(profile());
    return boca_manager->GetOnTaskSessionManager();
  }

  Browser* FindBocaSystemWebAppBrowser() {
    return ash::FindSystemWebAppBrowser(profile(), ash::SystemWebAppType::BOCA);
  }

  void VerifyNotificationShown(std::string notification_id,
                               bool notification_shown) {
    boca::MockClock::Get().Advance(boca::kOnTaskNotificationCountdownInterval);
    content::RunAllTasksUntilIdle();
    EXPECT_EQ(
        fake_notifications_delegate_ptr_->WasNotificationShown(notification_id),
        notification_shown);
  }

  void WaitForLockedModeCountdown() {
    // Simulate the full countdown duration to ensure generating the
    // notification.
    boca::MockClock::Get().Advance(
        ash::features::kBocaLockedModeCountdownDurationInSeconds.Get());
    content::RunAllTasksUntilIdle();

    // Simulate the full countdown duration to trigger completion.
    boca::MockClock::Get().Advance(
        ash::features::kBocaLockedModeCountdownDurationInSeconds.Get());
    content::RunAllTasksUntilIdle();
  }

  Profile* profile() { return browser()->profile(); }

  net::EmbeddedTestServer* https_server() { return &https_server_; }

 private:
  content::ContentMockCertVerifier mock_cert_verifier_;
  net::EmbeddedTestServer https_server_{net::EmbeddedTestServer::TYPE_HTTPS};
  raw_ptr<FakeOnTaskNotificationsManagerDelegate>
      fake_notifications_delegate_ptr_;
};

class OnTaskSessionManagerBrowserTest
    : public OnTaskSessionManagerBrowserTestBase {
 protected:
  OnTaskSessionManagerBrowserTest() {
    // Enable Boca and consumer experience for testing purposes. This is used
    // to set up the Boca SWA for OnTask.
    scoped_feature_list_.InitWithFeatures(
        /*enabled_features=*/{features::kBoca, features::kBocaConsumer,
                              features::kBocaLockedModeCustomCountdownDuration,
                              features::kOnDeviceSpeechRecognition,
                              features::kBocaKeepSWAOpenOnSessionEnded},
        /*disabled_features=*/{});
  }

 private:
  base::test::ScopedFeatureList scoped_feature_list_;
};

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldOpenTabsOnBundleUpdated) {
  content::TestNavigationObserver navigation_observer_1((GURL(kTestUrl1)));
  navigation_observer_1.StartWatchingNewWebContents();
  content::TestNavigationObserver navigation_observer_2((GURL(kTestUrl2)));
  navigation_observer_2.StartWatchingNewWebContents();

  // Start OnTask session and spawn two tabs outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  bundle.add_content_configs()->set_url(kTestUrl2);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer_1.Wait();
  navigation_observer_2.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 3);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));
  tab_strip_model->ActivateTabAt(2);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl2));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldAddTabsWhenAdditionalTabsFoundInBundle) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));

  // Add another tab to the bundle.
  bundle.add_content_configs()->set_url(kTestUrl2);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_EQ(tab_strip_model->count(), 3);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kTestUrl1));
  tab_strip_model->ActivateTabAt(2);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kTestUrl2));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldRemoveTabsWhenFewerTabsFoundInBundle) {
  content::TestNavigationObserver navigation_observer_1((GURL(kTestUrl1)));
  navigation_observer_1.StartWatchingNewWebContents();
  content::TestNavigationObserver navigation_observer_2((GURL(kTestUrl2)));
  navigation_observer_2.StartWatchingNewWebContents();

  // Start OnTask session and spawn two tabs outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  bundle.add_content_configs()->set_url(kTestUrl2);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer_1.Wait();
  navigation_observer_2.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 3);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));
  tab_strip_model->ActivateTabAt(2);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl2));

  // Remove one tab from the bundle.
  bundle.clear_content_configs();
  bundle.add_content_configs()->set_url(kTestUrl1);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kTestUrl1));
}

IN_PROC_BROWSER_TEST_F(
    OnTaskSessionManagerBrowserTest,
    ShouldPinAndUnpinBocaSWAWhenLockAndUnlockOnBundleUpdated) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());

  // Lock the boca app.
  bundle.set_locked(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  WaitForLockedModeCountdown();
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  EXPECT_TRUE(boca_app_browser->window()->IsToolbarVisible());

  // Unlock the boca app.
  bundle.set_locked(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  EXPECT_TRUE(boca_app_browser->window()->IsToolbarVisible());

  // Attempt to lock the boca app again to simulate real world scenario.
  bundle.set_locked(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  WaitForLockedModeCountdown();
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  EXPECT_TRUE(boca_app_browser->window()->IsToolbarVisible());

  // Unlock the Boca app to unblock test teardown that involves browser window
  // close.
  bundle.set_locked(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  EXPECT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldPinBocaSWAWhenPauseAndUnpauseOnBundleUpdated) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kTestUrl1));

  // Lock the boca app.
  bundle.set_locked(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  WaitForLockedModeCountdown();
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));

  // Pause the boca app.
  bundle.set_lock_to_app_home(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  auto* const browser_view =
      BrowserView::GetBrowserViewForBrowser(boca_app_browser);
  // Wait until immersive mode is disabled in pause mode.
  ASSERT_TRUE(base::test::RunUntil([&]() {
    return !browser_view->immersive_mode_controller()->IsEnabled();
  }));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kChromeBocaAppUntrustedIndexURL));

  // Unpause the boca app.
  bundle.set_lock_to_app_home(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  EXPECT_TRUE(browser_view->immersive_mode_controller()->IsEnabled());

  // Unlock the Boca app to unblock test teardown that involves browser window
  // close.
  bundle.set_locked(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  EXPECT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldSkipCountdownWhenPauseInUnlockedMode) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kTestUrl1));

  // Lock and pause the boca app.
  bundle.set_locked(true);
  bundle.set_lock_to_app_home(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  auto* const browser_view =
      BrowserView::GetBrowserViewForBrowser(boca_app_browser);
  // Wait until immersive mode is disabled in pause mode.
  ASSERT_TRUE(base::test::RunUntil([&]() {
    return !browser_view->immersive_mode_controller()->IsEnabled();
  }));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kChromeBocaAppUntrustedIndexURL));

  // Unpause the boca app.
  bundle.set_lock_to_app_home(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  EXPECT_TRUE(browser_view->immersive_mode_controller()->IsEnabled());

  // Unlock the Boca app to unblock test teardown that involves browser window
  // close.
  bundle.set_locked(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  EXPECT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldSkipCountdownWhenPauseDuringLockedModeCountdown) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kTestUrl1));

  // Lock the boca app.
  bundle.set_locked(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));

  // Pause the boca app.
  bundle.set_lock_to_app_home(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  const auto* const browser_view =
      BrowserView::GetBrowserViewForBrowser(boca_app_browser);
  // Wait until immersive mode is disabled in pause mode.
  ASSERT_TRUE(base::test::RunUntil([&]() {
    return !browser_view->immersive_mode_controller()->IsEnabled();
  }));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kChromeBocaAppUntrustedIndexURL));

  // Unpause the boca app.
  bundle.set_lock_to_app_home(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  EXPECT_TRUE(browser_view->immersive_mode_controller()->IsEnabled());

  // Unlock the Boca app to unblock test teardown that involves browser window
  // close.
  bundle.set_locked(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  EXPECT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldNotLockBocaSWAInAppReloadIfLockInProgress) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session, spawn one tab outside the homepage tab and lock the
  // boca app.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  bundle.set_locked(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  // Boca should not be locked before the full countdown, and locked after the
  // full countdown.
  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  ASSERT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  WaitForLockedModeCountdown();
  ASSERT_TRUE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
  EXPECT_FALSE(chromeos::wm::CanFloatWindow(
      boca_app_browser->window()->GetNativeWindow()));
  EXPECT_TRUE(boca_app_browser->window()->IsToolbarVisible());

  // Unlock the Boca app to unblock test teardown that involves browser window
  // close.
  bundle.set_locked(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  EXPECT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldApplyOpenNavRestrictionsToTabsOnBundleUpdated) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  ::boca::ContentConfig* const content_config =
      bundle.mutable_content_configs()->Add();
  content_config->set_url(kTestUrl1);
  // Set the tab navigation type to be 'Allow all navigation'.
  content_config->mutable_locked_navigation_options()->set_navigation_type(
      LockedNavigationOptions::OPEN_NAVIGATION);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));

  // Navigate the active tab to the new url.
  const GURL new_url(embedded_test_server()->GetURL("/test/new_page.html"));
  ASSERT_TRUE(ui_test_utils::NavigateToURL(boca_app_browser, new_url));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            new_url);
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldApplyBlockNavRestrictionsToTabsOnBundleUpdated) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  ::boca::ContentConfig* const content_config =
      bundle.mutable_content_configs()->Add();
  content_config->set_url(kTestUrl1);
  // Set the tab navigation type to be 'Just this page'.
  content_config->mutable_locked_navigation_options()->set_navigation_type(
      LockedNavigationOptions::BLOCK_NAVIGATION);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));

  // Navigate the active tab to the new url.
  const GURL new_url(embedded_test_server()->GetURL("/test/new_page.html"));
  ASSERT_TRUE(ui_test_utils::NavigateToURL(boca_app_browser, new_url));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldApplyDomainNavRestrictionsToTabsOnBundleUpdated) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  ::boca::ContentConfig* const content_config =
      bundle.mutable_content_configs()->Add();
  content_config->set_url(kTestUrl1);
  // Set the tab navigation type to be 'Anywhere on this site'.
  content_config->mutable_locked_navigation_options()->set_navigation_type(
      LockedNavigationOptions::DOMAIN_NAVIGATION);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));

  // Navigate the active tab to the new url.
  const GURL same_domain_url(
      embedded_test_server()->GetURL("test1.com", "/test/new_page.html"));
  ASSERT_TRUE(ui_test_utils::NavigateToURL(boca_app_browser, same_domain_url));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            same_domain_url);
  const GURL new_domain_url(
      embedded_test_server()->GetURL("test2.com", "/test/new_page.html"));
  ASSERT_TRUE(ui_test_utils::NavigateToURL(boca_app_browser, new_domain_url));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            same_domain_url);
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldApplyLimitedNavRestrictionsToTabsOnBundleUpdated) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  ::boca::ContentConfig* const content_config =
      bundle.mutable_content_configs()->Add();
  content_config->set_url(kTestUrl1);
  // Set the tab navigation type to be 'One link away from this page'.
  content_config->mutable_locked_navigation_options()->set_navigation_type(
      LockedNavigationOptions::LIMITED_NAVIGATION);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));

  // Navigate the active tab to the new url.
  const GURL one_level_url(
      embedded_test_server()->GetURL("/test/new_page.html"));
  ASSERT_TRUE(ui_test_utils::NavigateToURL(boca_app_browser, one_level_url));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            one_level_url);
  const GURL two_level_url(
      embedded_test_server()->GetURL("/test/new_page_2.html"));
  ASSERT_TRUE(ui_test_utils::NavigateToURL(boca_app_browser, two_level_url));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            one_level_url);
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldKeepBocaSWAOpenOnSessionEndWithFeatureEnabled) {
  const GURL boca_chrome_url = GURL(kChromeBocaAppUntrustedIndexURL);
  content::TestNavigationObserver navigation_observer(boca_chrome_url);
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  // End the session.
  GetOnTaskSessionManager()->OnSessionEnded(kSessionId);

  VerifyNotificationShown(kOnTaskSessionEndNotificationId, true);
  VerifyNotificationShown(kOnTaskBundleContentAddedNotificationId, false);
  VerifyNotificationShown(kOnTaskBundleContentRemovedNotificationId, false);
  EXPECT_EQ(FindBocaSystemWebAppBrowser(), boca_app_browser);
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       RestoreTabsSentByProviderOnAppReload) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn two tabs outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  bundle.add_content_configs()->set_url(kTestUrl2);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 3);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));
  tab_strip_model->ActivateTabAt(2);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl2));

  // Open a new tab that is not sent by the provider from Boca homepage.
  tab_strip_model->ActivateTabAt(0);
  const GURL new_url(embedded_test_server()->GetURL("/test/new_page.html"));
  ASSERT_TRUE(ui_test_utils::NavigateToURLWithDisposition(
      boca_app_browser, new_url, WindowOpenDisposition::NEW_FOREGROUND_TAB,
      ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP));
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            new_url);
  ASSERT_EQ(tab_strip_model->count(), 4);

  // Attempt an app reload and verify tabs sent by the provider are restored.
  GetOnTaskSessionManager()->OnAppReloaded();
  ASSERT_EQ(tab_strip_model->count(), 3);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kTestUrl1));
  tab_strip_model->ActivateTabAt(2);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetVisibleURL(),
            GURL(kTestUrl2));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldOpenBocaSWAOnSessionTakeover) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl1));

  // End the session and start another session.
  GetOnTaskSessionManager()->OnSessionEnded(kSessionId);
  content::TestNavigationObserver navigation_observer_2((GURL(kTestUrl2)));
  navigation_observer_2.StartWatchingNewWebContents();
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId2,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle_2;
  bundle_2.add_content_configs()->set_url(kTestUrl2);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle_2);
  navigation_observer_2.Wait();

  Browser* const boca_app_browser_2 = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser_2, NotNull());
  ASSERT_TRUE(boca_app_browser_2->IsLockedForOnTask());
  auto* const tab_strip_model_2 = boca_app_browser_2->tab_strip_model();
  ASSERT_EQ(tab_strip_model_2->count(), 2);
  tab_strip_model_2->ActivateTabAt(1);
  EXPECT_EQ(tab_strip_model_2->GetActiveWebContents()->GetLastCommittedURL(),
            GURL(kTestUrl2));
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldMuteAndUnmuteTabsAudioWhenLockAndUnlock) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  OnTaskSessionManager* const on_task_session_manager =
      GetOnTaskSessionManager();
  on_task_session_manager->OnSessionStarted(kSessionId, ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  on_task_session_manager->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());

  // Open first browser window.
  Browser* const browser_1 = browser();
  chrome::NewTab(browser_1);
  ASSERT_TRUE(ui_test_utils::NavigateToURL(browser_1, GURL(kTestUrl1)));

  // Open second browser window.
  Browser* const browser_2 =
      Browser::Create(Browser::CreateParams(profile(), true));
  chrome::NewTab(browser_2);
  ASSERT_TRUE(ui_test_utils::NavigateToURL(browser_2, GURL(kTestUrl2)));

  // Lock the boca app and tabs in boca app browser are not muted.
  bundle.set_locked(true);
  on_task_session_manager->OnBundleUpdated(bundle);
  auto* const tab_strip_model = boca_app_browser->tab_strip_model();
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_FALSE(tab_strip_model->GetActiveWebContents()->IsAudioMuted());

  // Tabs in other browsers are muted.
  EXPECT_TRUE(
      browser_1->tab_strip_model()->GetActiveWebContents()->IsAudioMuted());
  EXPECT_TRUE(
      browser_2->tab_strip_model()->GetActiveWebContents()->IsAudioMuted());

  // Unlock the boca app and tabs in boca app browser are not muted.
  bundle.set_locked(false);
  on_task_session_manager->OnBundleUpdated(bundle);
  ASSERT_EQ(tab_strip_model->count(), 2);
  tab_strip_model->ActivateTabAt(1);
  EXPECT_FALSE(tab_strip_model->GetActiveWebContents()->IsAudioMuted());

  // Tabs in other browsers are unmuted.
  EXPECT_FALSE(
      browser_1->tab_strip_model()->GetActiveWebContents()->IsAudioMuted());
  EXPECT_FALSE(
      browser_2->tab_strip_model()->GetActiveWebContents()->IsAudioMuted());
}

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerBrowserTest,
                       ShouldRespectLatestPinStateOnBundleUpdated) {
  content::TestNavigationObserver navigation_observer((GURL(kTestUrl1)));
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session and spawn one tab outside the homepage tab.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  ::boca::Bundle bundle;
  bundle.add_content_configs()->set_url(kTestUrl1);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  ASSERT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));

  // Pause and then unlock the boca app.
  bundle.set_locked(true);
  bundle.set_lock_to_app_home(true);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  bundle.set_locked(false);
  bundle.set_lock_to_app_home(false);
  GetOnTaskSessionManager()->OnBundleUpdated(bundle);
  EXPECT_FALSE(platform_util::IsBrowserLockedFullscreen(boca_app_browser));
}

class OnTaskSessionManagerCloseSWAOnSessionEndBrowserTest
    : public OnTaskSessionManagerBrowserTestBase {
 protected:
  OnTaskSessionManagerCloseSWAOnSessionEndBrowserTest() {
    scoped_feature_list_.InitWithFeatures(
        /*enabled_features=*/{features::kBoca, features::kBocaConsumer,
                              features::kBocaLockedModeCustomCountdownDuration,
                              features::kOnDeviceSpeechRecognition},
        /*disabled_features=*/{features::kBocaKeepSWAOpenOnSessionEnded});
  }

 private:
  base::test::ScopedFeatureList scoped_feature_list_;
};

IN_PROC_BROWSER_TEST_F(OnTaskSessionManagerCloseSWAOnSessionEndBrowserTest,
                       ShouldCloseBocaSWAOnSessionEnd) {
  const GURL boca_chrome_url = GURL(kChromeBocaAppUntrustedIndexURL);
  content::TestNavigationObserver navigation_observer(boca_chrome_url);
  navigation_observer.StartWatchingNewWebContents();

  // Start OnTask session.
  GetOnTaskSessionManager()->OnSessionStarted(kSessionId,
                                              ::boca::UserIdentity());
  navigation_observer.Wait();

  Browser* const boca_app_browser = FindBocaSystemWebAppBrowser();
  ASSERT_THAT(boca_app_browser, NotNull());
  ASSERT_TRUE(boca_app_browser->IsLockedForOnTask());
  // End the session.
  GetOnTaskSessionManager()->OnSessionEnded(kSessionId);
  // Wait until the browser actually gets closed.
  ui_test_utils::WaitForBrowserToClose();
  VerifyNotificationShown(kOnTaskSessionEndNotificationId, true);
  VerifyNotificationShown(kOnTaskBundleContentAddedNotificationId, false);
  VerifyNotificationShown(kOnTaskBundleContentRemovedNotificationId, false);
  ASSERT_THAT(FindBocaSystemWebAppBrowser(), IsNull());
}

}  // namespace
}  // namespace ash::boca