Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/sync/sessions/browser_list_router_helper.h" | |
| 6 | |
| 7 #include "base/stl_util.h" | |
| 8 #include "chrome/browser/sync/sessions/sync_sessions_web_contents_router.h" | |
| 9 #include "chrome/browser/sync/sessions/sync_sessions_web_contents_router_factory .h" | |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 11 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 12 | |
| 13 namespace sync_sessions { | |
| 14 | |
| 15 class BrowserListRouterHelperTest : public BrowserWithTestWindowTest { | |
| 16 protected: | |
| 17 ~BrowserListRouterHelperTest() override {} | |
| 18 | |
| 19 std::set<Browser*> attached_browsers(SyncSessionsWebContentsRouter* router) { | |
|
skym
2017/05/15 20:58:01
The naming for this method is odd. GetAttachedBrow
Patrick Noland
2017/05/15 21:56:51
n/a since I removed this.
| |
| 20 return router->browser_list_helper_->attached_browsers_; | |
| 21 } | |
| 22 }; | |
| 23 | |
| 24 TEST_F(BrowserListRouterHelperTest, ObservationScopedToSingleProfile) { | |
| 25 std::unique_ptr<TestingProfile> profile_1 = | |
| 26 base::WrapUnique(BrowserWithTestWindowTest::CreateProfile()); | |
| 27 std::unique_ptr<TestingProfile> profile_2 = | |
| 28 base::WrapUnique(BrowserWithTestWindowTest::CreateProfile()); | |
| 29 | |
| 30 std::unique_ptr<Browser> browser_2 = base::WrapUnique(CreateBrowser( | |
| 31 profile_2.get(), browser()->type(), false, CreateBrowserWindow())); | |
| 32 | |
| 33 SyncSessionsWebContentsRouter* router_1 = | |
| 34 SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile( | |
| 35 profile_1.get()); | |
| 36 SyncSessionsWebContentsRouter* router_2 = | |
| 37 SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile( | |
| 38 profile_2.get()); | |
| 39 | |
| 40 // Check that the initial browsers are only attached to their respective | |
| 41 // browser list helpers. | |
| 42 std::set<Browser*> attached_browsers_1 = attached_browsers(router_1); | |
| 43 std::set<Browser*> attached_browsers_2 = attached_browsers(router_2); | |
| 44 std::set<Browser*> intersection = | |
| 45 base::STLSetIntersection<std::set<Browser*>>(attached_browsers_1, | |
| 46 attached_browsers_2); | |
| 47 EXPECT_EQ(0u, intersection.size()); | |
| 48 | |
| 49 // Add a browser for each profile. | |
| 50 std::unique_ptr<Browser> new_browser_in_first_profile = | |
| 51 base::WrapUnique(CreateBrowser(profile_1.get(), browser()->type(), false, | |
| 52 CreateBrowserWindow())); | |
| 53 std::unique_ptr<Browser> new_browser_in_second_profile = | |
| 54 base::WrapUnique(CreateBrowser(profile_2.get(), browser()->type(), false, | |
| 55 CreateBrowserWindow())); | |
| 56 // Check that the added browsers are only attached to their respective browser | |
|
skym
2017/05/15 20:58:01
Would it be useful to check that browser counts as
Patrick Noland
2017/05/15 21:56:51
n/a since I removed this
| |
| 57 // list helpers. | |
| 58 attached_browsers_1 = attached_browsers(router_1); | |
| 59 attached_browsers_2 = attached_browsers(router_2); | |
| 60 intersection = base::STLSetIntersection<std::set<Browser*>>( | |
| 61 attached_browsers_1, attached_browsers_2); | |
| 62 EXPECT_EQ(0u, intersection.size()); | |
| 63 | |
| 64 // Cleanup needed for manually created browsers so they don't complain about | |
|
skym
2017/05/15 20:58:01
Who is "they"? Why does this test case care?
Is i
Patrick Noland
2017/05/15 21:56:51
I will fix this comment, but the destructor for Br
| |
| 65 // having open tabs when destructing. | |
| 66 browser_2->tab_strip_model()->CloseAllTabs(); | |
| 67 new_browser_in_first_profile->tab_strip_model()->CloseAllTabs(); | |
| 68 new_browser_in_second_profile->tab_strip_model()->CloseAllTabs(); | |
| 69 } | |
|
skym
2017/05/15 20:58:01
Would also be cool to test ~BrowserListRouterHelpe
Patrick Noland
2017/05/15 21:56:51
Acknowledged.
| |
| 70 | |
| 71 } // namespace sync_sessions | |
| OLD | NEW |