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 #include "components/sync_sessions/synced_tab_delegate.h" | |
| 13 | |
| 14 namespace sync_sessions { | |
| 15 | |
| 16 class MockLocalSessionEventHandler : public LocalSessionEventHandler { | |
|
skym
2017/05/16 16:11:25
Thanks for doing this!
| |
| 17 public: | |
| 18 void OnLocalTabModified(SyncedTabDelegate* modified_tab) override { | |
| 19 seen_urls_.push_back(modified_tab->GetVirtualURLAtIndex( | |
| 20 modified_tab->GetCurrentEntryIndex())); | |
| 21 } | |
| 22 | |
| 23 void OnFaviconsChanged(const std::set<GURL>& page_urls, | |
| 24 const GURL& icon_url) override {} | |
| 25 | |
| 26 std::vector<GURL>* seen_urls() { return &seen_urls_; } | |
| 27 | |
| 28 private: | |
| 29 std::vector<GURL> seen_urls_; | |
| 30 }; | |
| 31 | |
| 32 class BrowserListRouterHelperTest : public BrowserWithTestWindowTest { | |
| 33 protected: | |
| 34 ~BrowserListRouterHelperTest() override {} | |
| 35 | |
| 36 MockLocalSessionEventHandler handler_1; | |
| 37 MockLocalSessionEventHandler handler_2; | |
| 38 }; | |
| 39 | |
| 40 TEST_F(BrowserListRouterHelperTest, ObservationScopedToSingleProfile) { | |
| 41 TestingProfile* profile_1 = profile(); | |
| 42 std::unique_ptr<TestingProfile> profile_2 = | |
| 43 base::WrapUnique(BrowserWithTestWindowTest::CreateProfile()); | |
| 44 | |
| 45 std::unique_ptr<Browser> browser_2 = base::WrapUnique(CreateBrowser( | |
| 46 profile_2.get(), browser()->type(), false, CreateBrowserWindow())); | |
|
skym
2017/05/16 16:11:25
Is this ASAN failure because your BrowserWindow ne
| |
| 47 | |
| 48 SyncSessionsWebContentsRouter* router_1 = | |
| 49 SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile( | |
| 50 profile_1); | |
| 51 SyncSessionsWebContentsRouter* router_2 = | |
| 52 SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile( | |
| 53 profile_2.get()); | |
| 54 | |
| 55 router_1->StartRoutingTo(&handler_1); | |
| 56 router_2->StartRoutingTo(&handler_2); | |
| 57 | |
| 58 GURL gurl_1("http://foo1.com"); | |
| 59 GURL gurl_2("http://foo2.com"); | |
| 60 AddTab(browser(), gurl_1); | |
| 61 AddTab(browser_2.get(), gurl_2); | |
| 62 | |
| 63 std::vector<GURL>* handler_1_urls = handler_1.seen_urls(); | |
| 64 EXPECT_FALSE(std::find(handler_1_urls->begin(), handler_1_urls->end(), | |
|
skym
2017/05/16 16:11:25
Also, base/stl_util.h has a function for this! Wha
| |
| 65 gurl_1) == handler_1_urls->end()); | |
| 66 EXPECT_TRUE(std::find(handler_1_urls->begin(), handler_1_urls->end(), | |
| 67 gurl_2) == handler_1_urls->end()); | |
| 68 | |
| 69 std::vector<GURL>* handler_2_urls = handler_2.seen_urls(); | |
| 70 EXPECT_FALSE(std::find(handler_2_urls->begin(), handler_2_urls->end(), | |
| 71 gurl_2) == handler_2_urls->end()); | |
| 72 EXPECT_TRUE(std::find(handler_2_urls->begin(), handler_2_urls->end(), | |
| 73 gurl_1) == handler_2_urls->end()); | |
| 74 | |
| 75 // Add a browser for each profile. | |
| 76 std::unique_ptr<Browser> new_browser_in_first_profile = | |
| 77 base::WrapUnique(CreateBrowser(profile_1, browser()->type(), false, | |
| 78 CreateBrowserWindow())); | |
| 79 std::unique_ptr<Browser> new_browser_in_second_profile = | |
| 80 base::WrapUnique(CreateBrowser(profile_2.get(), browser()->type(), false, | |
| 81 CreateBrowserWindow())); | |
| 82 | |
| 83 GURL gurl_3("http://foo3.com"); | |
| 84 GURL gurl_4("http://foo4.com"); | |
| 85 AddTab(new_browser_in_first_profile.get(), gurl_3); | |
| 86 AddTab(new_browser_in_second_profile.get(), gurl_4); | |
| 87 | |
| 88 handler_1_urls = handler_1.seen_urls(); | |
| 89 EXPECT_FALSE(std::find(handler_1_urls->begin(), handler_1_urls->end(), | |
| 90 gurl_3) == handler_1_urls->end()); | |
| 91 EXPECT_TRUE(std::find(handler_1_urls->begin(), handler_1_urls->end(), | |
| 92 gurl_4) == handler_1_urls->end()); | |
| 93 | |
| 94 handler_2_urls = handler_2.seen_urls(); | |
| 95 EXPECT_FALSE(std::find(handler_2_urls->begin(), handler_2_urls->end(), | |
| 96 gurl_4) == handler_2_urls->end()); | |
| 97 EXPECT_TRUE(std::find(handler_2_urls->begin(), handler_2_urls->end(), | |
| 98 gurl_3) == handler_2_urls->end()); | |
| 99 | |
| 100 // Cleanup needed for manually created browsers so they don't complain about | |
| 101 // having open tabs when destructing. | |
| 102 browser_2->tab_strip_model()->CloseAllTabs(); | |
| 103 new_browser_in_first_profile->tab_strip_model()->CloseAllTabs(); | |
| 104 new_browser_in_second_profile->tab_strip_model()->CloseAllTabs(); | |
| 105 } | |
| 106 | |
| 107 } // namespace sync_sessions | |
| OLD | NEW |