Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: chrome/browser/sync/sessions/browser_list_router_helper_unittest.cc

Issue 2887513002: [sync] Scope BrowserListRouterHelper to browsers with a matching profile (Closed)
Patch Set: fix last memory leak Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 {
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 BrowserWithTestWindowTest::CreateProfile());
44
45 std::unique_ptr<BrowserWindow> window_2(CreateBrowserWindow());
46 std::unique_ptr<Browser> browser_2(
47 CreateBrowser(profile_2.get(), browser()->type(), false, window_2.get()));
48
49 SyncSessionsWebContentsRouter* router_1 =
50 SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile(
51 profile_1);
52 SyncSessionsWebContentsRouter* router_2 =
53 SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile(
54 profile_2.get());
55
56 router_1->StartRoutingTo(&handler_1);
57 router_2->StartRoutingTo(&handler_2);
58
59 GURL gurl_1("http://foo1.com");
60 GURL gurl_2("http://foo2.com");
61 AddTab(browser(), gurl_1);
62 AddTab(browser_2.get(), gurl_2);
63
64 std::vector<GURL>* handler_1_urls = handler_1.seen_urls();
65 EXPECT_TRUE(base::ContainsValue(*handler_1_urls, gurl_1));
66 EXPECT_FALSE(base::ContainsValue(*handler_1_urls, gurl_2));
67
68 std::vector<GURL>* handler_2_urls = handler_2.seen_urls();
69 EXPECT_TRUE(base::ContainsValue(*handler_2_urls, gurl_2));
70 EXPECT_FALSE(base::ContainsValue(*handler_2_urls, gurl_1));
71
72 // Add a browser for each profile.
73 std::unique_ptr<BrowserWindow> window_3(CreateBrowserWindow());
74 std::unique_ptr<BrowserWindow> window_4(CreateBrowserWindow());
75
76 std::unique_ptr<Browser> new_browser_in_first_profile(
77 CreateBrowser(profile_1, browser()->type(), false, window_3.get()));
78 std::unique_ptr<Browser> new_browser_in_second_profile(
79 CreateBrowser(profile_2.get(), browser()->type(), false, window_4.get()));
80
81 GURL gurl_3("http://foo3.com");
82 GURL gurl_4("http://foo4.com");
83 AddTab(new_browser_in_first_profile.get(), gurl_3);
84 AddTab(new_browser_in_second_profile.get(), gurl_4);
85
86 handler_1_urls = handler_1.seen_urls();
87 EXPECT_TRUE(base::ContainsValue(*handler_1_urls, gurl_3));
88 EXPECT_FALSE(base::ContainsValue(*handler_1_urls, gurl_4));
89
90 handler_2_urls = handler_2.seen_urls();
91 EXPECT_TRUE(base::ContainsValue(*handler_2_urls, gurl_4));
92 EXPECT_FALSE(base::ContainsValue(*handler_2_urls, gurl_3));
93
94 // Cleanup needed for manually created browsers so they don't complain about
95 // having open tabs when destructing.
96 browser_2->tab_strip_model()->CloseAllTabs();
97 new_browser_in_first_profile->tab_strip_model()->CloseAllTabs();
98 new_browser_in_second_profile->tab_strip_model()->CloseAllTabs();
99 }
100
101 } // namespace sync_sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698