| OLD | NEW | 
|---|
| 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()); |  | 
| 23   MOCK_METHOD2(GenerateSnapshot, void(Browser* browser, | 22   MOCK_METHOD2(GenerateSnapshot, void(Browser* browser, | 
| 24                                       base::WeakPtr<Observer> observer)); | 23                                       base::WeakPtr<Observer> observer)); | 
| 25   MOCK_METHOD4(SendToMobile, void(const base::DictionaryValue& mobile, | 24   MOCK_METHOD4(SendToMobile, void(const base::DictionaryValue* mobile, | 
| 26                                   const FilePath& snapshot, | 25                                   const FilePath& snapshot, | 
| 27                                   Browser* browser, | 26                                   Browser* browser, | 
| 28                                   base::WeakPtr<Observer> observer)); | 27                                   base::WeakPtr<Observer> observer)); | 
| 29   MOCK_METHOD1(DeleteSnapshot, void(const FilePath& snapshot)); | 28   MOCK_METHOD1(DeleteSnapshot, void(const FilePath& snapshot)); | 
| 30   MOCK_CONST_METHOD1(LogMetric, void(ChromeToMobileService::Metric)); | 29   MOCK_CONST_METHOD1(LogMetric, void(ChromeToMobileService::Metric)); | 
| 31 | 30 | 
| 32   // A set of mock mobile devices, kept in lieu of the list in profile prefs. | 31   // A set of mock mobile devices, kept in lieu of the list in profile prefs. | 
| 33   base::ListValue mobiles_; | 32   base::ListValue mobiles_; | 
| 34 }; | 33 }; | 
| 35 | 34 | 
| 36 void MockChromeToMobileService::AddDevices(size_t count) { | 35 void MockChromeToMobileService::AddDevices(size_t count) { | 
| 37   for(size_t i = 0; i < count; i++) { | 36   for(size_t i = 0; i < count; i++) { | 
| 38     base::DictionaryValue* device = new base::DictionaryValue(); | 37     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"); | 
| 40     mobiles_.Append(device); | 41     mobiles_.Append(device); | 
| 41   } | 42   } | 
| 42 } | 43 } | 
| 43 | 44 | 
| 44 const base::ListValue* MockChromeToMobileService::GetMobiles() const { | 45 const base::ListValue* MockChromeToMobileService::GetMobiles() const { | 
| 45   return &mobiles_; | 46   return &mobiles_; | 
| 46 } | 47 } | 
| 47 | 48 | 
| 48 namespace { | 49 namespace { | 
| 49 | 50 | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 108   MockChromeToMobileService service_; | 109   MockChromeToMobileService service_; | 
| 109   ChromeToMobileBubbleController* controller_;  // Weak, owns self. | 110   ChromeToMobileBubbleController* controller_;  // Weak, owns self. | 
| 110 | 111 | 
| 111  private: | 112  private: | 
| 112   NSWindow* window_;  // Weak, owned by controller. | 113   NSWindow* window_;  // Weak, owned by controller. | 
| 113 | 114 | 
| 114   DISALLOW_COPY_AND_ASSIGN(ChromeToMobileBubbleControllerTest); | 115   DISALLOW_COPY_AND_ASSIGN(ChromeToMobileBubbleControllerTest); | 
| 115 }; | 116 }; | 
| 116 | 117 | 
| 117 TEST_F(ChromeToMobileBubbleControllerTest, OneDevice) { | 118 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); | 
| 120   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 122   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 
| 121   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 123   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 
| 122 | 124 | 
| 123   service_.AddDevices(1); | 125   service_.AddDevices(1); | 
| 124   CreateBubble(); | 126   CreateBubble(); | 
| 125   CheckWindow(/*radio_buttons=*/0); | 127   CheckWindow(/*radio_buttons=*/0); | 
| 126 } | 128 } | 
| 127 | 129 | 
| 128 TEST_F(ChromeToMobileBubbleControllerTest, TwoDevices) { | 130 TEST_F(ChromeToMobileBubbleControllerTest, TwoDevices) { | 
| 129   EXPECT_CALL(service_, RequestMobileListUpdate()); |  | 
| 130   EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); | 131   EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); | 
|  | 132   EXPECT_CALL(service_, SendToMobile(testing::_, testing::_, | 
|  | 133                                      testing::_, testing::_)).Times(0); | 
| 131   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 134   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 
| 132   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 135   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 
| 133 | 136 | 
| 134   service_.AddDevices(2); | 137   service_.AddDevices(2); | 
| 135   CreateBubble(); | 138   CreateBubble(); | 
| 136   CheckWindow(/*radio_buttons=*/2); | 139   CheckWindow(/*radio_buttons=*/2); | 
| 137 } | 140 } | 
| 138 | 141 | 
| 139 TEST_F(ChromeToMobileBubbleControllerTest, ThreeDevices) { | 142 TEST_F(ChromeToMobileBubbleControllerTest, ThreeDevices) { | 
| 140   EXPECT_CALL(service_, RequestMobileListUpdate()); |  | 
| 141   EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); | 143   EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); | 
|  | 144   EXPECT_CALL(service_, SendToMobile(testing::_, testing::_, | 
|  | 145                                      testing::_, testing::_)).Times(0); | 
| 142   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 146   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 
| 143   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 147   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 
| 144 | 148 | 
| 145   service_.AddDevices(3); | 149   service_.AddDevices(3); | 
| 146   CreateBubble(); | 150   CreateBubble(); | 
| 147   CheckWindow(/*radio_buttons=*/3); | 151   CheckWindow(/*radio_buttons=*/3); | 
| 148 } | 152 } | 
| 149 | 153 | 
| 150 TEST_F(ChromeToMobileBubbleControllerTest, SendWithoutSnapshot) { | 154 TEST_F(ChromeToMobileBubbleControllerTest, SendWithoutSnapshot) { | 
| 151   FilePath path; | 155   FilePath path; | 
| 152   EXPECT_CALL(service_, RequestMobileListUpdate()); |  | 
| 153   EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); | 156   EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); | 
| 154   EXPECT_CALL(service_, SendToMobile(testing::_, path, NULL, testing::_)); | 157   EXPECT_CALL(service_, SendToMobile(testing::_, path, NULL, testing::_)); | 
| 155   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 158   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 
| 156   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 159   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 
| 157 | 160 | 
| 158   service_.AddDevices(1); | 161   service_.AddDevices(1); | 
| 159   CreateBubble(); | 162   CreateBubble(); | 
| 160   [controller_ send:nil]; | 163   [controller_ send:nil]; | 
| 161 } | 164 } | 
| 162 | 165 | 
| 163 TEST_F(ChromeToMobileBubbleControllerTest, SendWithSnapshot) { | 166 TEST_F(ChromeToMobileBubbleControllerTest, SendWithSnapshot) { | 
| 164   FilePath path("path.mht"); | 167   FilePath path("path.mht"); | 
| 165   EXPECT_CALL(service_, RequestMobileListUpdate()); |  | 
| 166   EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); | 168   EXPECT_CALL(service_, GenerateSnapshot(NULL, testing::_)); | 
| 167   EXPECT_CALL(service_, SendToMobile(testing::_, path, NULL, testing::_)); | 169   EXPECT_CALL(service_, SendToMobile(testing::_, path, NULL, testing::_)); | 
| 168   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 170   EXPECT_CALL(service_, DeleteSnapshot(testing::_)); | 
| 169   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 171   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::BUBBLE_SHOWN)); | 
| 170   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::SNAPSHOT_GENERATED)); | 172   EXPECT_CALL(service_, LogMetric(ChromeToMobileService::SNAPSHOT_GENERATED)); | 
| 171 | 173 | 
| 172   service_.AddDevices(1); | 174   service_.AddDevices(1); | 
| 173   CreateBubble(); | 175   CreateBubble(); | 
| 174   ChromeToMobileBubbleNotificationBridge* bridge = [controller_ bridge]; | 176   ChromeToMobileBubbleNotificationBridge* bridge = [controller_ bridge]; | 
| 175   bridge->SnapshotGenerated(path, 1); | 177   bridge->SnapshotGenerated(path, 1); | 
| 176   [controller_ setSendCopy:YES]; | 178   [controller_ setSendCopy:YES]; | 
| 177   [controller_ send:nil]; | 179   [controller_ send:nil]; | 
| 178   // Send failure to prevent the bubble from posting a task to close itself. | 180   // Send failure to prevent the bubble from posting a task to close itself. | 
| 179   bridge->OnSendComplete(false); | 181   bridge->OnSendComplete(false); | 
| 180 } | 182 } | 
| 181 | 183 | 
| 182 }  // namespace | 184 }  // namespace | 
| OLD | NEW | 
|---|