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/sync_sessions_web_contents_router.h" | |
6 #include "base/memory/ptr_util.h" | |
7 #include "chrome/browser/sync/sessions/sync_sessions_web_contents_router_factory .h" | |
8 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | |
9 #include "chrome/test/base/testing_profile.h" | |
10 #include "content/public/test/test_browser_thread_bundle.h" | |
11 #include "content/public/test/web_contents_tester.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace sync_sessions { | |
15 | |
16 class StartSyncFlareMock { | |
17 public: | |
18 StartSyncFlareMock() {} | |
19 ~StartSyncFlareMock() {} | |
20 | |
21 void StartSyncFlare(syncer::ModelType type) { was_run_ = true; } | |
22 | |
23 bool was_run() { return was_run_; } | |
24 | |
25 private: | |
26 bool was_run_ = false; | |
27 }; | |
28 | |
29 class SyncSessionsWebContentsRouterTest : public testing::Test { | |
30 protected: | |
31 ~SyncSessionsWebContentsRouterTest() override {} | |
32 | |
33 void SetUp() override { | |
34 router_ = | |
35 SyncSessionsWebContentsRouterFactory::GetInstance()->GetForProfile( | |
36 &profile_); | |
37 test_contents_.reset( | |
38 content::WebContentsTester::CreateTestWebContents(&profile_, nullptr)); | |
39 } | |
40 | |
41 SyncSessionsWebContentsRouter* router() { return router_; } | |
42 content::WebContents* test_contents() { return test_contents_.get(); } | |
43 | |
44 private: | |
45 content::TestBrowserThreadBundle thread_bundle_; | |
46 TestingProfile profile_; | |
47 SyncSessionsWebContentsRouter* router_; | |
48 std::unique_ptr<content::WebContents> test_contents_; | |
49 }; | |
50 | |
51 TEST_F(SyncSessionsWebContentsRouterTest, FlareNotRun) { | |
52 StartSyncFlareMock mock; | |
53 router()->InjectStartSyncFlare( | |
54 base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock))); | |
55 | |
56 // There's no delegate for the tab, so the flare shouldn't run. | |
57 router()->NotifyTabModified(test_contents(), false); | |
58 EXPECT_FALSE(mock.was_run()); | |
59 | |
60 TabContentsSyncedTabDelegate::CreateForWebContents(test_contents()); | |
61 | |
62 // There's a delegate for the tab, but it's not a load completed event, so the | |
63 // flare still shouldn't run. | |
64 router()->NotifyTabModified(test_contents(), false); | |
65 EXPECT_FALSE(mock.was_run()); | |
66 } | |
67 | |
68 TEST_F(SyncSessionsWebContentsRouterTest, FlareRunsForLoadCompleted) { | |
69 TabContentsSyncedTabDelegate::CreateForWebContents(test_contents()); | |
70 | |
71 StartSyncFlareMock mock; | |
72 router()->InjectStartSyncFlare( | |
skym
2017/04/18 22:39:52
What about not having a flare and making sure we d
Patrick Noland
2017/04/18 22:53:19
Done.
| |
73 base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock))); | |
74 | |
75 // There's a delegate for the tab, and it's a load completed event, so the | |
76 // flare should run. | |
77 router()->NotifyTabModified(test_contents(), true); | |
78 EXPECT_TRUE(mock.was_run()); | |
79 } | |
80 | |
81 } // namespace sync_sessions | |
OLD | NEW |