OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ios/chrome/browser/device_sharing/device_sharing_manager.h" | 5 #include "ios/chrome/browser/device_sharing/device_sharing_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/mac/scoped_nsobject.h" | |
11 #import "components/handoff/handoff_manager.h" | 10 #import "components/handoff/handoff_manager.h" |
12 #include "components/handoff/pref_names_ios.h" | 11 #include "components/handoff/pref_names_ios.h" |
13 #include "components/sync_preferences/testing_pref_service_syncable.h" | 12 #include "components/sync_preferences/testing_pref_service_syncable.h" |
14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 13 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
15 #include "ios/web/public/test/test_web_thread_bundle.h" | 14 #include "ios/web/public/test/test_web_thread_bundle.h" |
16 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
17 #import "third_party/ocmock/OCMock/OCMock.h" | 16 #import "third_party/ocmock/OCMock/OCMock.h" |
18 #import "third_party/ocmock/gtest_support.h" | 17 #import "third_party/ocmock/gtest_support.h" |
19 #include "url/gurl.h" | 18 #include "url/gurl.h" |
20 | 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
21 @interface TestDeviceSharingManager : DeviceSharingManager | 24 @interface TestDeviceSharingManager : DeviceSharingManager |
22 + (HandoffManager*)createHandoffManager; | 25 + (HandoffManager*)createHandoffManager; |
23 @end | 26 @end |
24 | 27 |
25 @implementation TestDeviceSharingManager | 28 @implementation TestDeviceSharingManager |
26 + (HandoffManager*)createHandoffManager { | 29 + (HandoffManager*)createHandoffManager { |
27 return [OCMockObject niceMockForClass:[HandoffManager class]]; | 30 return [OCMockObject niceMockForClass:[HandoffManager class]]; |
28 } | 31 } |
29 @end | 32 @end |
30 | 33 |
31 namespace { | 34 namespace { |
32 | 35 |
33 class DeviceSharingManagerTest : public PlatformTest { | 36 class DeviceSharingManagerTest : public PlatformTest { |
34 protected: | 37 protected: |
35 DeviceSharingManagerTest() | 38 DeviceSharingManagerTest() |
36 : PlatformTest(), | 39 : PlatformTest(), |
37 kTestURL1("http://test_sharing_1.html"), | 40 kTestURL1("http://test_sharing_1.html"), |
38 kTestURL2("http://test_sharing_2.html") {} | 41 kTestURL2("http://test_sharing_2.html") {} |
39 | 42 |
40 void SetUp() override { | 43 void SetUp() override { |
41 PlatformTest::SetUp(); | 44 PlatformTest::SetUp(); |
42 TestChromeBrowserState::Builder mainBrowserStateBuilder; | 45 TestChromeBrowserState::Builder mainBrowserStateBuilder; |
43 chrome_browser_state_ = mainBrowserStateBuilder.Build(); | 46 chrome_browser_state_ = mainBrowserStateBuilder.Build(); |
44 sharing_manager_.reset([[TestDeviceSharingManager alloc] init]); | 47 sharing_manager_ = [[TestDeviceSharingManager alloc] init]; |
45 } | 48 } |
46 | 49 |
47 void TearDown() override { | 50 void TearDown() override { |
48 [sharing_manager_ updateBrowserState:NULL]; | 51 [sharing_manager_ updateBrowserState:NULL]; |
49 sharing_manager_.reset(); | 52 sharing_manager_ = nil; |
50 } | 53 } |
51 | 54 |
52 const GURL kTestURL1; | 55 const GURL kTestURL1; |
53 const GURL kTestURL2; | 56 const GURL kTestURL2; |
54 web::TestWebThreadBundle thread_bundle_; | 57 web::TestWebThreadBundle thread_bundle_; |
55 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 58 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
56 base::scoped_nsobject<DeviceSharingManager> sharing_manager_; | 59 DeviceSharingManager* sharing_manager_; |
57 }; | 60 }; |
58 | 61 |
59 TEST_F(DeviceSharingManagerTest, NoMainBrowserState) { | 62 TEST_F(DeviceSharingManagerTest, NoMainBrowserState) { |
60 EXPECT_FALSE([sharing_manager_ handoffManager]); | 63 EXPECT_FALSE([sharing_manager_ handoffManager]); |
61 // Updating the active URL should be a no-op. | 64 // Updating the active URL should be a no-op. |
62 [sharing_manager_ updateActiveURL:GURL("http://test")]; | 65 [sharing_manager_ updateActiveURL:GURL("http://test")]; |
63 EXPECT_FALSE([sharing_manager_ handoffManager]); | 66 EXPECT_FALSE([sharing_manager_ handoffManager]); |
64 } | 67 } |
65 | 68 |
66 TEST_F(DeviceSharingManagerTest, ShareOneUrl) { | 69 TEST_F(DeviceSharingManagerTest, ShareOneUrl) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 TEST_F(DeviceSharingManagerTest, DisableHandoffViaPrefs) { | 107 TEST_F(DeviceSharingManagerTest, DisableHandoffViaPrefs) { |
105 [sharing_manager_ updateBrowserState:chrome_browser_state_.get()]; | 108 [sharing_manager_ updateBrowserState:chrome_browser_state_.get()]; |
106 EXPECT_TRUE([sharing_manager_ handoffManager]); | 109 EXPECT_TRUE([sharing_manager_ handoffManager]); |
107 sync_preferences::TestingPrefServiceSyncable* prefs = | 110 sync_preferences::TestingPrefServiceSyncable* prefs = |
108 chrome_browser_state_->GetTestingPrefService(); | 111 chrome_browser_state_->GetTestingPrefService(); |
109 prefs->SetBoolean(prefs::kIosHandoffToOtherDevices, false); | 112 prefs->SetBoolean(prefs::kIosHandoffToOtherDevices, false); |
110 EXPECT_FALSE([sharing_manager_ handoffManager]); | 113 EXPECT_FALSE([sharing_manager_ handoffManager]); |
111 } | 114 } |
112 | 115 |
113 } // namespace | 116 } // namespace |
OLD | NEW |