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

Side by Side Diff: chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller_unittest.mm

Issue 10861038: Revert 152609 - Integrate invalidation API into ChromeToMobileService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/values.h" 5 #include "base/values.h"
6 #include "chrome/browser/chrome_to_mobile_service.h" 6 #include "chrome/browser/chrome_to_mobile_service.h"
7 #import "chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.h" 7 #import "chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.h"
8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
10 10
11 // Caution!!! Do not conflict with this class name elsewhere! 11 // Caution!!! Do not conflict with this class name elsewhere!
12 class MockChromeToMobileService : public ChromeToMobileService { 12 class MockChromeToMobileService : public ChromeToMobileService {
13 public: 13 public:
14 MockChromeToMobileService() : ChromeToMobileService(NULL) {} 14 MockChromeToMobileService() : ChromeToMobileService(NULL) {}
15 15
16 // A utility function to add mock devices. 16 // A utility function to add mock devices.
17 void AddDevices(size_t count); 17 void AddDevices(size_t count);
18 18
19 // ChromeToMobileService overrides: 19 // ChromeToMobileService overrides:
20 virtual const base::ListValue* GetMobiles() const OVERRIDE; 20 virtual const base::ListValue* GetMobiles() const OVERRIDE;
21 21
22 MOCK_METHOD0(RequestMobileListUpdate, void());
22 MOCK_METHOD2(GenerateSnapshot, void(Browser* browser, 23 MOCK_METHOD2(GenerateSnapshot, void(Browser* browser,
23 base::WeakPtr<Observer> observer)); 24 base::WeakPtr<Observer> observer));
24 MOCK_METHOD4(SendToMobile, void(const base::DictionaryValue* mobile, 25 MOCK_METHOD4(SendToMobile, void(const base::DictionaryValue& mobile,
25 const FilePath& snapshot, 26 const FilePath& snapshot,
26 Browser* browser, 27 Browser* browser,
27 base::WeakPtr<Observer> observer)); 28 base::WeakPtr<Observer> observer));
28 MOCK_METHOD1(DeleteSnapshot, void(const FilePath& snapshot)); 29 MOCK_METHOD1(DeleteSnapshot, void(const FilePath& snapshot));
29 MOCK_CONST_METHOD1(LogMetric, void(ChromeToMobileService::Metric)); 30 MOCK_CONST_METHOD1(LogMetric, void(ChromeToMobileService::Metric));
30 31
31 // A set of mock mobile devices, kept in lieu of the list in profile prefs. 32 // A set of mock mobile devices, kept in lieu of the list in profile prefs.
32 base::ListValue mobiles_; 33 base::ListValue mobiles_;
33 }; 34 };
34 35
35 void MockChromeToMobileService::AddDevices(size_t count) { 36 void MockChromeToMobileService::AddDevices(size_t count) {
36 for(size_t i = 0; i < count; i++) { 37 for(size_t i = 0; i < count; i++) {
37 base::DictionaryValue* device = new base::DictionaryValue(); 38 base::DictionaryValue* device = new base::DictionaryValue();
38 device->SetString("type", "Device Type");
39 device->SetString("name", "Device Name"); 39 device->SetString("name", "Device Name");
40 device->SetString("id", "Device ID");
41 mobiles_.Append(device); 40 mobiles_.Append(device);
42 } 41 }
43 } 42 }
44 43
45 const base::ListValue* MockChromeToMobileService::GetMobiles() const { 44 const base::ListValue* MockChromeToMobileService::GetMobiles() const {
46 return &mobiles_; 45 return &mobiles_;
47 } 46 }
48 47
49 namespace { 48 namespace {
50 49
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 MockChromeToMobileService service_; 108 MockChromeToMobileService service_;
110 ChromeToMobileBubbleController* controller_; // Weak, owns self. 109 ChromeToMobileBubbleController* controller_; // Weak, owns self.
111 110
112 private: 111 private:
113 NSWindow* window_; // Weak, owned by controller. 112 NSWindow* window_; // Weak, owned by controller.
114 113
115 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileBubbleControllerTest); 114 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileBubbleControllerTest);
116 }; 115 };
117 116
118 TEST_F(ChromeToMobileBubbleControllerTest, OneDevice) { 117 TEST_F(ChromeToMobileBubbleControllerTest, OneDevice) {
118 EXPECT_CALL(service_, RequestMobileListUpdate());
119 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); 119 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_));
120 EXPECT_CALL(service_, SendToMobile(testing::_, testing::_,
121 testing::_, testing::_)).Times(0);
122 EXPECT_CALL(service_, DeleteSnapshot(testing::_)); 120 EXPECT_CALL(service_, DeleteSnapshot(testing::_));
123 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); 121 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN));
124 122
125 service_.AddDevices(1); 123 service_.AddDevices(1);
126 CreateBubble(); 124 CreateBubble();
127 CheckWindow(/*radio_buttons=*/0); 125 CheckWindow(/*radio_buttons=*/0);
128 } 126 }
129 127
130 TEST_F(ChromeToMobileBubbleControllerTest, TwoDevices) { 128 TEST_F(ChromeToMobileBubbleControllerTest, TwoDevices) {
129 EXPECT_CALL(service_, RequestMobileListUpdate());
131 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); 130 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_));
132 EXPECT_CALL(service_, SendToMobile(testing::_, testing::_,
133 testing::_, testing::_)).Times(0);
134 EXPECT_CALL(service_, DeleteSnapshot(testing::_)); 131 EXPECT_CALL(service_, DeleteSnapshot(testing::_));
135 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); 132 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN));
136 133
137 service_.AddDevices(2); 134 service_.AddDevices(2);
138 CreateBubble(); 135 CreateBubble();
139 CheckWindow(/*radio_buttons=*/2); 136 CheckWindow(/*radio_buttons=*/2);
140 } 137 }
141 138
142 TEST_F(ChromeToMobileBubbleControllerTest, ThreeDevices) { 139 TEST_F(ChromeToMobileBubbleControllerTest, ThreeDevices) {
140 EXPECT_CALL(service_, RequestMobileListUpdate());
143 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); 141 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_));
144 EXPECT_CALL(service_, SendToMobile(testing::_, testing::_,
145 testing::_, testing::_)).Times(0);
146 EXPECT_CALL(service_, DeleteSnapshot(testing::_)); 142 EXPECT_CALL(service_, DeleteSnapshot(testing::_));
147 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); 143 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN));
148 144
149 service_.AddDevices(3); 145 service_.AddDevices(3);
150 CreateBubble(); 146 CreateBubble();
151 CheckWindow(/*radio_buttons=*/3); 147 CheckWindow(/*radio_buttons=*/3);
152 } 148 }
153 149
154 TEST_F(ChromeToMobileBubbleControllerTest, SendWithoutSnapshot) { 150 TEST_F(ChromeToMobileBubbleControllerTest, SendWithoutSnapshot) {
155 FilePath path; 151 FilePath path;
152 EXPECT_CALL(service_, RequestMobileListUpdate());
156 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); 153 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_));
157 EXPECT_CALL(service_, SendToMobile(testing::_, path, NULL, testing::_)); 154 EXPECT_CALL(service_, SendToMobile(testing::_, path, NULL, testing::_));
158 EXPECT_CALL(service_, DeleteSnapshot(testing::_)); 155 EXPECT_CALL(service_, DeleteSnapshot(testing::_));
159 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); 156 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN));
160 157
161 service_.AddDevices(1); 158 service_.AddDevices(1);
162 CreateBubble(); 159 CreateBubble();
163 [controller_ send:nil]; 160 [controller_ send:nil];
164 } 161 }
165 162
166 TEST_F(ChromeToMobileBubbleControllerTest, SendWithSnapshot) { 163 TEST_F(ChromeToMobileBubbleControllerTest, SendWithSnapshot) {
167 FilePath path("path.mht"); 164 FilePath path("path.mht");
165 EXPECT_CALL(service_, RequestMobileListUpdate());
168 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); 166 EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_));
169 EXPECT_CALL(service_, SendToMobile(testing::_, path, NULL, testing::_)); 167 EXPECT_CALL(service_, SendToMobile(testing::_, path, NULL, testing::_));
170 EXPECT_CALL(service_, DeleteSnapshot(testing::_)); 168 EXPECT_CALL(service_, DeleteSnapshot(testing::_));
171 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); 169 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN));
172 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::SNAPSHOT_GENERATED)); 170 EXPECT_CALL(service_, LogMetric(ChromeToMobileService::SNAPSHOT_GENERATED));
173 171
174 service_.AddDevices(1); 172 service_.AddDevices(1);
175 CreateBubble(); 173 CreateBubble();
176 ChromeToMobileBubbleNotificationBridge* bridge = [controller_ bridge]; 174 ChromeToMobileBubbleNotificationBridge* bridge = [controller_ bridge];
177 bridge->SnapshotGenerated(path, 1); 175 bridge->SnapshotGenerated(path, 1);
178 [controller_ setSendCopy:YES]; 176 [controller_ setSendCopy:YES];
179 [controller_ send:nil]; 177 [controller_ send:nil];
180 // Send failure to prevent the bubble from posting a task to close itself. 178 // Send failure to prevent the bubble from posting a task to close itself.
181 bridge->OnSendComplete(false); 179 bridge->OnSendComplete(false);
182 } 180 }
183 181
184 } // namespace 182 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698