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

Side by Side Diff: ios/chrome/browser/device_sharing/device_sharing_manager_unittest.mm

Issue 2484703003: [ios] Adds code to support the iOS Handoff feature. (Closed)
Patch Set: Review. Created 4 years, 1 month 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 2015 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 "ios/chrome/browser/device_sharing/device_sharing_manager.h"
6
7 #include <memory>
8
9 #include "base/mac/foundation_util.h"
10 #include "base/mac/scoped_nsobject.h"
11 #import "components/handoff/handoff_manager.h"
12 #include "components/sync_preferences/testing_pref_service_syncable.h"
13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
14 #include "ios/chrome/browser/pref_names.h"
15 #include "ios/web/public/test/test_web_thread_bundle.h"
16 #include "testing/platform_test.h"
17 #import "third_party/ocmock/OCMock/OCMock.h"
18 #import "third_party/ocmock/gtest_support.h"
19 #include "url/gurl.h"
20
21 @interface TestDeviceSharingManager : DeviceSharingManager
22 + (HandoffManager*)createHandoffManager;
23 @end
24
25 @implementation TestDeviceSharingManager
26 + (HandoffManager*)createHandoffManager {
27 return [OCMockObject niceMockForClass:[HandoffManager class]];
28 }
29 @end
30
31 namespace {
32
33 class DeviceSharingManagerTest : public PlatformTest {
34 protected:
35 DeviceSharingManagerTest()
36 : PlatformTest(),
37 kTestURL1("http://test_sharing_1.html"),
38 kTestURL2("http://test_sharing_2.html") {}
39
40 void SetUp() override {
41 PlatformTest::SetUp();
42 TestChromeBrowserState::Builder mainBrowserStateBuilder;
43 chrome_browser_state_ = mainBrowserStateBuilder.Build();
44 sync_preferences::TestingPrefServiceSyncable* prefs =
45 chrome_browser_state_->GetTestingPrefService();
46 [HandoffManager registerBrowserStatePrefs:prefs->registry()];
47 sharing_manager_.reset([[TestDeviceSharingManager alloc] init]);
48 }
49
50 void TearDown() override {
51 [sharing_manager_ updateBrowserState:NULL];
52 sharing_manager_.reset();
53 }
54
55 const GURL kTestURL1;
56 const GURL kTestURL2;
57 web::TestWebThreadBundle thread_bundle_;
58 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
59 base::scoped_nsobject<DeviceSharingManager> sharing_manager_;
60 };
61
62 TEST_F(DeviceSharingManagerTest, NoMainBrowserState) {
63 EXPECT_FALSE([sharing_manager_ handoffManager]);
64 // Updating the active URL should be a no-op.
65 [sharing_manager_ updateActiveURL:GURL("http://test")];
66 EXPECT_FALSE([sharing_manager_ handoffManager]);
67 }
68
69 TEST_F(DeviceSharingManagerTest, ShareOneUrl) {
70 [sharing_manager_ updateBrowserState:chrome_browser_state_.get()];
71 EXPECT_TRUE([sharing_manager_ handoffManager]);
72 OCMockObject* mock_handoff_manager =
73 (OCMockObject*)[sharing_manager_ handoffManager];
74
75 [[mock_handoff_manager expect] updateActiveURL:kTestURL1];
76 [sharing_manager_ updateActiveURL:kTestURL1];
77 EXPECT_OCMOCK_VERIFY(mock_handoff_manager);
78 }
79
80 TEST_F(DeviceSharingManagerTest, ShareTwoUrls) {
81 [sharing_manager_ updateBrowserState:chrome_browser_state_.get()];
82 EXPECT_TRUE([sharing_manager_ handoffManager]);
83 OCMockObject* mock_handoff_manager =
84 (OCMockObject*)[sharing_manager_ handoffManager];
85
86 [[mock_handoff_manager expect] updateActiveURL:kTestURL1];
87 [[mock_handoff_manager expect] updateActiveURL:kTestURL2];
88 [sharing_manager_ updateActiveURL:kTestURL1];
89 [sharing_manager_ updateActiveURL:kTestURL2];
90 EXPECT_OCMOCK_VERIFY(mock_handoff_manager);
91 }
92
93 TEST_F(DeviceSharingManagerTest, ResetMainBrowserStateAfterShare) {
94 [sharing_manager_ updateBrowserState:chrome_browser_state_.get()];
95 EXPECT_TRUE([sharing_manager_ handoffManager]);
96 OCMockObject* mock_handoff_manager =
97 (OCMockObject*)[sharing_manager_ handoffManager];
98
99 [[mock_handoff_manager expect] updateActiveURL:kTestURL1];
100 [sharing_manager_ updateActiveURL:kTestURL1];
101 EXPECT_OCMOCK_VERIFY(mock_handoff_manager);
102
103 [sharing_manager_ updateBrowserState:NULL];
104 EXPECT_FALSE([sharing_manager_ handoffManager]);
105 }
106
107 TEST_F(DeviceSharingManagerTest, DisableHandoffViaPrefs) {
108 [sharing_manager_ updateBrowserState:chrome_browser_state_.get()];
109 EXPECT_TRUE([sharing_manager_ handoffManager]);
110 sync_preferences::TestingPrefServiceSyncable* prefs =
111 chrome_browser_state_->GetTestingPrefService();
112 prefs->SetBoolean(prefs::kIosHandoffToOtherDevices, false);
113 EXPECT_FALSE([sharing_manager_ handoffManager]);
114 }
115
116 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698