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

Side by Side Diff: chrome/browser/chrome_to_mobile_service_unittest.cc

Issue 13197004: Draft: InvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Passes tests Created 7 years, 8 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 "chrome/browser/chrome_to_mobile_service.h" 5 #include "chrome/browser/chrome_to_mobile_service.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/chrome_to_mobile_service_factory.h" 9 #include "chrome/browser/chrome_to_mobile_service_factory.h"
10 #include "chrome/browser/command_updater.h" 10 #include "chrome/browser/command_updater.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 private: 47 private:
48 FeatureSwitch::ScopedOverride enable_action_box_; 48 FeatureSwitch::ScopedOverride enable_action_box_;
49 49
50 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileServiceTest); 50 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileServiceTest);
51 }; 51 };
52 52
53 // Chrome To Mobile is currently gated on the Action Box UI, 53 // Chrome To Mobile is currently gated on the Action Box UI,
54 // so need to enable this feature for the test. 54 // so need to enable this feature for the test.
55 ChromeToMobileServiceTest::ChromeToMobileServiceTest() 55 ChromeToMobileServiceTest::ChromeToMobileServiceTest()
56 : enable_action_box_(FeatureSwitch::action_box(), true) {} 56 : enable_action_box_(FeatureSwitch::action_box(), true) {
57 }
57 58
58 ChromeToMobileServiceTest::~ChromeToMobileServiceTest() {} 59 ChromeToMobileServiceTest::~ChromeToMobileServiceTest() {}
59 60
60 ChromeToMobileService* ChromeToMobileServiceTest::GetService() const { 61 ChromeToMobileService* ChromeToMobileServiceTest::GetService() const {
61 return ChromeToMobileServiceFactory::GetForProfile(profile()); 62 return ChromeToMobileServiceFactory::GetForProfile(profile());
62 } 63 }
63 64
64 bool ChromeToMobileServiceTest::UpdateAndGetVerifiedCommandState() { 65 bool ChromeToMobileServiceTest::UpdateAndGetVerifiedCommandState() {
65 bool state = ChromeToMobileService::UpdateAndGetCommandState(browser()); 66 bool state = ChromeToMobileService::UpdateAndGetCommandState(browser());
66 CommandUpdater* updater = browser()->command_controller()->command_updater(); 67 CommandUpdater* updater = browser()->command_controller()->command_updater();
67 EXPECT_EQ(state, updater->IsCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE)); 68 EXPECT_EQ(state, updater->IsCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE));
68 return state; 69 return state;
69 } 70 }
70 71
71 void ChromeToMobileServiceTest::SetDeviceCount(size_t count) { 72 void ChromeToMobileServiceTest::SetDeviceCount(size_t count) {
72 ListValue mobiles; 73 ListValue mobiles;
73 for (size_t i = 0; i < count; ++i) 74 for (size_t i = 0; i < count; ++i)
74 mobiles.Append(new DictionaryValue()); 75 mobiles.Append(new DictionaryValue());
75 profile()->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, mobiles); 76 profile()->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, mobiles);
76 } 77 }
77 78
78 void ChromeToMobileServiceTest::FulfillFeatureRequirements() { 79 void ChromeToMobileServiceTest::FulfillFeatureRequirements() {
79 AddTab(browser(), GURL("http://foo")); 80 AddTab(browser(), GURL("http://foo"));
80 SetDeviceCount(1); 81 SetDeviceCount(1);
81 GetService()->OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED); 82 GetService()->OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED);
82 EXPECT_TRUE(UpdateAndGetVerifiedCommandState()); 83 EXPECT_TRUE(UpdateAndGetVerifiedCommandState());
83 } 84 }
84 85
85 // Test that GetMobiles and HasMobiles require Sync Invalidations being enabled. 86 // Test that GetMobiles and HasMobiles require Sync Invalidations being enabled.
86 TEST_F(ChromeToMobileServiceTest, GetMobiles) { 87 TEST_F(ChromeToMobileServiceTest, DISABLED_GetMobiles) {
87 ChromeToMobileService* service = GetService(); 88 ChromeToMobileService* service = GetService();
88 EXPECT_EQ(NULL, service->GetMobiles()); 89 EXPECT_EQ(NULL, service->GetMobiles());
89 EXPECT_FALSE(service->HasMobiles()); 90 EXPECT_FALSE(service->HasMobiles());
90 91
91 // Add a mock mobile device to the profile prefs. 92 // Add a mock mobile device to the profile prefs.
92 SetDeviceCount(1); 93 SetDeviceCount(1);
93 94
94 // GetMobiles() still returns NULL until Sync Invalidations are enabled. 95 // GetMobiles() still returns NULL until Sync Invalidations are enabled.
95 EXPECT_EQ(NULL, service->GetMobiles()); 96 EXPECT_EQ(NULL, service->GetMobiles());
96 EXPECT_FALSE(service->HasMobiles()); 97 EXPECT_FALSE(service->HasMobiles());
(...skipping 12 matching lines...) Expand all
109 // GetMobiles() returns NULL after Sync Invalidations are disabled. 110 // GetMobiles() returns NULL after Sync Invalidations are disabled.
110 service->OnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR); 111 service->OnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR);
111 EXPECT_EQ(NULL, service->GetMobiles()); 112 EXPECT_EQ(NULL, service->GetMobiles());
112 EXPECT_FALSE(service->HasMobiles()); 113 EXPECT_FALSE(service->HasMobiles());
113 service->OnInvalidatorStateChange(syncer::INVALIDATION_CREDENTIALS_REJECTED); 114 service->OnInvalidatorStateChange(syncer::INVALIDATION_CREDENTIALS_REJECTED);
114 EXPECT_EQ(NULL, service->GetMobiles()); 115 EXPECT_EQ(NULL, service->GetMobiles());
115 EXPECT_FALSE(service->HasMobiles()); 116 EXPECT_FALSE(service->HasMobiles());
116 } 117 }
117 118
118 // Test fulfilling the requirements to enable the feature. 119 // Test fulfilling the requirements to enable the feature.
119 TEST_F(ChromeToMobileServiceTest, RequirementsToEnable) { 120 TEST_F(ChromeToMobileServiceTest, DISABLED_RequirementsToEnable) {
120 // Navigate to a page with a URL that is valid to send. 121 // Navigate to a page with a URL that is valid to send.
121 AddTab(browser(), GURL("http://foo")); 122 AddTab(browser(), GURL("http://foo"));
122 EXPECT_FALSE(UpdateAndGetVerifiedCommandState()); 123 EXPECT_FALSE(UpdateAndGetVerifiedCommandState());
123 124
124 // Add a mock mobile device to the profile prefs. 125 // Add a mock mobile device to the profile prefs.
125 SetDeviceCount(1); 126 SetDeviceCount(1);
126 EXPECT_FALSE(UpdateAndGetVerifiedCommandState()); 127 EXPECT_FALSE(UpdateAndGetVerifiedCommandState());
127 128
128 // Send a fake notification that Sync Invalidations are enabled. 129 // Send a fake notification that Sync Invalidations are enabled.
129 GetService()->OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED); 130 GetService()->OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED);
130 EXPECT_TRUE(UpdateAndGetVerifiedCommandState()); 131 EXPECT_TRUE(UpdateAndGetVerifiedCommandState());
131 } 132 }
132 133
133 // Test that the feature handles mobile device count changes properly. 134 // Test that the feature handles mobile device count changes properly.
134 TEST_F(ChromeToMobileServiceTest, MobileDevicesAreRequired) { 135 TEST_F(ChromeToMobileServiceTest, DISABLED_MobileDevicesAreRequired) {
135 FulfillFeatureRequirements(); 136 FulfillFeatureRequirements();
136 137
137 // Removing all devices disables the feature. 138 // Removing all devices disables the feature.
138 SetDeviceCount(0); 139 SetDeviceCount(0);
139 EXPECT_FALSE(UpdateAndGetVerifiedCommandState()); 140 EXPECT_FALSE(UpdateAndGetVerifiedCommandState());
140 141
141 // Restoring mobile devices re-enables the feature. 142 // Restoring mobile devices re-enables the feature.
142 SetDeviceCount(1); 143 SetDeviceCount(1);
143 EXPECT_TRUE(UpdateAndGetVerifiedCommandState()); 144 EXPECT_TRUE(UpdateAndGetVerifiedCommandState());
144 SetDeviceCount(3); 145 SetDeviceCount(3);
145 EXPECT_TRUE(UpdateAndGetVerifiedCommandState()); 146 EXPECT_TRUE(UpdateAndGetVerifiedCommandState());
146 } 147 }
147 148
148 // Test that the feature handles Sync Invalidations state changes properly. 149 // Test that the feature handles Sync Invalidations state changes properly.
149 TEST_F(ChromeToMobileServiceTest, SyncInvalidationsAreRequired) { 150 TEST_F(ChromeToMobileServiceTest, DISABLED_SyncInvalidationsAreRequired) {
150 FulfillFeatureRequirements(); 151 FulfillFeatureRequirements();
151 152
152 // Disabling Sync Invalidations disables the feature. 153 // Disabling Sync Invalidations disables the feature.
153 GetService()->OnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR); 154 GetService()->OnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR);
154 EXPECT_FALSE(UpdateAndGetVerifiedCommandState()); 155 EXPECT_FALSE(UpdateAndGetVerifiedCommandState());
155 156
156 // Re-enabling Sync Invalidations re-enables the feature. 157 // Re-enabling Sync Invalidations re-enables the feature.
157 GetService()->OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED); 158 GetService()->OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED);
158 EXPECT_TRUE(UpdateAndGetVerifiedCommandState()); 159 EXPECT_TRUE(UpdateAndGetVerifiedCommandState());
159 } 160 }
160 161
161 // Test that the feature handles various page URLs properly. 162 // Test that the feature handles various page URLs properly.
162 TEST_F(ChromeToMobileServiceTest, CertainSchemesAreRequired) { 163 TEST_F(ChromeToMobileServiceTest, DISABLED_CertainSchemesAreRequired) {
163 FulfillFeatureRequirements(); 164 FulfillFeatureRequirements();
164 165
165 // Only http:, https:, and ftp: URLs are valid to send. 166 // Only http:, https:, and ftp: URLs are valid to send.
166 struct { 167 struct {
167 std::string url; 168 std::string url;
168 bool enabled; 169 bool enabled;
169 } cases[] = { 170 } cases[] = {
170 { "http://foo", true }, { "https://foo", true }, { "ftp://foo", true }, 171 { "http://foo", true }, { "https://foo", true }, { "ftp://foo", true },
171 { "about:foo", false }, { "chrome://foo", false }, { "file://foo", false }, 172 { "about:foo", false }, { "chrome://foo", false }, { "file://foo", false },
172 { "data://foo", false }, { "view-source:foo", false }, 173 { "data://foo", false }, { "view-source:foo", false },
173 }; 174 };
174 175
175 content::NavigationController* controller = 176 content::NavigationController* controller =
176 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); 177 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
177 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 178 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
178 NavigateAndCommit(controller, GURL(cases[i].url)); 179 NavigateAndCommit(controller, GURL(cases[i].url));
179 EXPECT_EQ(cases[i].enabled, UpdateAndGetVerifiedCommandState()); 180 EXPECT_EQ(cases[i].enabled, UpdateAndGetVerifiedCommandState());
180 } 181 }
181 } 182 }
182 183
183 // Ensure that only relevant notifications invalidate the access token. 184 // Ensure that only relevant notifications invalidate the access token.
184 TEST_F(ChromeToMobileServiceTest, TokenNotifications) { 185 TEST_F(ChromeToMobileServiceTest, DISABLED_TokenNotifications) {
185 const char dummy_string[] = "dummy"; 186 const char dummy_string[] = "dummy";
186 ChromeToMobileService* service = GetService(); 187 ChromeToMobileService* service = GetService();
187 service->SetAccessTokenForTest(dummy_string); 188 service->SetAccessTokenForTest(dummy_string);
188 ASSERT_FALSE(service->GetAccessTokenForTest().empty()); 189 ASSERT_FALSE(service->GetAccessTokenForTest().empty());
189 190
190 // Send dummy service/token details (should not clear the token). 191 // Send dummy service/token details (should not clear the token).
191 TokenService::TokenAvailableDetails dummy_details(dummy_string, dummy_string); 192 TokenService::TokenAvailableDetails dummy_details(dummy_string, dummy_string);
192 service->Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE, 193 service->Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE,
193 content::Source<ChromeToMobileServiceTest>(this), 194 content::Source<ChromeToMobileServiceTest>(this),
194 content::Details<TokenService::TokenAvailableDetails>(&dummy_details)); 195 content::Details<TokenService::TokenAvailableDetails>(&dummy_details));
195 EXPECT_FALSE(service->GetAccessTokenForTest().empty()); 196 EXPECT_FALSE(service->GetAccessTokenForTest().empty());
196 197
197 // Send a Gaia OAuth2 Login service dummy token (should clear the token). 198 // Send a Gaia OAuth2 Login service dummy token (should clear the token).
198 TokenService::TokenAvailableDetails login_details( 199 TokenService::TokenAvailableDetails login_details(
199 GaiaConstants::kGaiaOAuth2LoginRefreshToken, dummy_string); 200 GaiaConstants::kGaiaOAuth2LoginRefreshToken, dummy_string);
200 service->Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE, 201 service->Observe(chrome::NOTIFICATION_TOKEN_AVAILABLE,
201 content::Source<ChromeToMobileServiceTest>(this), 202 content::Source<ChromeToMobileServiceTest>(this),
202 content::Details<TokenService::TokenAvailableDetails>(&login_details)); 203 content::Details<TokenService::TokenAvailableDetails>(&login_details));
203 EXPECT_TRUE(service->GetAccessTokenForTest().empty()); 204 EXPECT_TRUE(service->GetAccessTokenForTest().empty());
204 } 205 }
205 206
206 } // namespace 207 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698