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

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_sync_observer_unittest.cc

Issue 1374053002: Remove AboutToNavigateRenderFrame, issue custom notification for DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased, win test fix Created 5 years, 2 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/sync/one_click_signin_sync_observer.h" 5 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
(...skipping 21 matching lines...) Expand all
32 class MockWebContentsObserver : public content::WebContentsObserver { 32 class MockWebContentsObserver : public content::WebContentsObserver {
33 public: 33 public:
34 explicit MockWebContentsObserver(content::WebContents* web_contents) 34 explicit MockWebContentsObserver(content::WebContents* web_contents)
35 : content::WebContentsObserver(web_contents) {} 35 : content::WebContentsObserver(web_contents) {}
36 virtual ~MockWebContentsObserver() {} 36 virtual ~MockWebContentsObserver() {}
37 37
38 // A hook to verify that the OneClickSigninSyncObserver initiated a redirect 38 // A hook to verify that the OneClickSigninSyncObserver initiated a redirect
39 // to the continue URL. Navigations in unit_tests never complete, but a 39 // to the continue URL. Navigations in unit_tests never complete, but a
40 // navigation start is a sufficient signal for the purposes of this test. 40 // navigation start is a sufficient signal for the purposes of this test.
41 // Listening for this call also has the advantage of being synchronous. 41 // Listening for this call also has the advantage of being synchronous.
42 MOCK_METHOD2(AboutToNavigateRenderFrame, void(content::RenderFrameHost*, 42 MOCK_METHOD2(DidStartNavigationToPendingEntry,
43 content::RenderFrameHost*)); 43 void(const GURL&, content::NavigationController::ReloadType));
44 }; 44 };
45 45
46 class OneClickTestProfileSyncService : public TestProfileSyncService { 46 class OneClickTestProfileSyncService : public TestProfileSyncService {
47 public: 47 public:
48 ~OneClickTestProfileSyncService() override {} 48 ~OneClickTestProfileSyncService() override {}
49 49
50 // Helper routine to be used in conjunction with 50 // Helper routine to be used in conjunction with
51 // BrowserContextKeyedServiceFactory::SetTestingFactory(). 51 // BrowserContextKeyedServiceFactory::SetTestingFactory().
52 static scoped_ptr<KeyedService> Build(content::BrowserContext* profile) { 52 static scoped_ptr<KeyedService> Build(content::BrowserContext* profile) {
53 return make_scoped_ptr( 53 return make_scoped_ptr(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Verify that if no Sync service is present, e.g. because Sync is disabled, the 163 // Verify that if no Sync service is present, e.g. because Sync is disabled, the
164 // observer immediately loads the continue URL. 164 // observer immediately loads the continue URL.
165 TEST_F(OneClickSigninSyncObserverTest, NoSyncService_RedirectsImmediately) { 165 TEST_F(OneClickSigninSyncObserverTest, NoSyncService_RedirectsImmediately) {
166 // Simulate disabling Sync. 166 // Simulate disabling Sync.
167 sync_service_ = 167 sync_service_ =
168 static_cast<OneClickTestProfileSyncService*>( 168 static_cast<OneClickTestProfileSyncService*>(
169 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 169 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
170 profile(), BuildNullService)); 170 profile(), BuildNullService));
171 171
172 // The observer should immediately redirect to the continue URL. 172 // The observer should immediately redirect to the continue URL.
173 EXPECT_CALL(*web_contents_observer_, AboutToNavigateRenderFrame(_, _)); 173 EXPECT_CALL(*web_contents_observer_, DidStartNavigationToPendingEntry(_, _));
174 CreateSyncObserver(kContinueUrl); 174 CreateSyncObserver(kContinueUrl);
175 EXPECT_EQ(GURL(kContinueUrl), web_contents()->GetVisibleURL()); 175 EXPECT_EQ(GURL(kContinueUrl), web_contents()->GetVisibleURL());
176 176
177 // The |sync_observer_| will be destroyed asynchronously, so manually pump 177 // The |sync_observer_| will be destroyed asynchronously, so manually pump
178 // the message loop to wait for the destruction. 178 // the message loop to wait for the destruction.
179 content::RunAllPendingInMessageLoop(); 179 content::RunAllPendingInMessageLoop();
180 } 180 }
181 181
182 // Verify that when the WebContents is destroyed without any Sync notifications 182 // Verify that when the WebContents is destroyed without any Sync notifications
183 // firing, the observer cleans up its memory without loading the continue URL. 183 // firing, the observer cleans up its memory without loading the continue URL.
184 TEST_F(OneClickSigninSyncObserverTest, WebContentsDestroyed) { 184 TEST_F(OneClickSigninSyncObserverTest, WebContentsDestroyed) {
185 EXPECT_CALL(*web_contents_observer_, 185 EXPECT_CALL(*web_contents_observer_,
186 AboutToNavigateRenderFrame(_, _)).Times(0); 186 DidStartNavigationToPendingEntry(_, _)).Times(0);
187 CreateSyncObserver(kContinueUrl); 187 CreateSyncObserver(kContinueUrl);
188 SetContents(NULL); 188 SetContents(NULL);
189 } 189 }
190 190
191 // Verify that when Sync is configured successfully, the observer loads the 191 // Verify that when Sync is configured successfully, the observer loads the
192 // continue URL and cleans up after itself. 192 // continue URL and cleans up after itself.
193 TEST_F(OneClickSigninSyncObserverTest, 193 TEST_F(OneClickSigninSyncObserverTest,
194 OnSyncStateChanged_SyncConfiguredSuccessfully) { 194 OnSyncStateChanged_SyncConfiguredSuccessfully) {
195 CreateSyncObserver(kContinueUrl); 195 CreateSyncObserver(kContinueUrl);
196 sync_service_->set_first_setup_in_progress(false); 196 sync_service_->set_first_setup_in_progress(false);
197 sync_service_->set_sync_active(true); 197 sync_service_->set_sync_active(true);
198 198
199 EXPECT_CALL(*web_contents_observer_, AboutToNavigateRenderFrame(_, _)); 199 EXPECT_CALL(*web_contents_observer_, DidStartNavigationToPendingEntry(_, _));
200 sync_service_->NotifyObservers(); 200 sync_service_->NotifyObservers();
201 EXPECT_EQ(GURL(kContinueUrl), web_contents()->GetVisibleURL()); 201 EXPECT_EQ(GURL(kContinueUrl), web_contents()->GetVisibleURL());
202 } 202 }
203 203
204 // Verify that when Sync configuration fails, the observer does not load the 204 // Verify that when Sync configuration fails, the observer does not load the
205 // continue URL, but still cleans up after itself. 205 // continue URL, but still cleans up after itself.
206 TEST_F(OneClickSigninSyncObserverTest, 206 TEST_F(OneClickSigninSyncObserverTest,
207 OnSyncStateChanged_SyncConfigurationFailed) { 207 OnSyncStateChanged_SyncConfigurationFailed) {
208 CreateSyncObserver(kContinueUrl); 208 CreateSyncObserver(kContinueUrl);
209 sync_service_->set_first_setup_in_progress(false); 209 sync_service_->set_first_setup_in_progress(false);
210 sync_service_->set_sync_active(false); 210 sync_service_->set_sync_active(false);
211 211
212 EXPECT_CALL(*web_contents_observer_, 212 EXPECT_CALL(*web_contents_observer_,
213 AboutToNavigateRenderFrame(_, _)).Times(0); 213 DidStartNavigationToPendingEntry(_, _)).Times(0);
214 sync_service_->NotifyObservers(); 214 sync_service_->NotifyObservers();
215 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL()); 215 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL());
216 } 216 }
217 217
218 // Verify that when Sync sends a notification while setup is not yet complete, 218 // Verify that when Sync sends a notification while setup is not yet complete,
219 // the observer does not load the continue URL, and continues to wait. 219 // the observer does not load the continue URL, and continues to wait.
220 TEST_F(OneClickSigninSyncObserverTest, 220 TEST_F(OneClickSigninSyncObserverTest,
221 OnSyncStateChanged_SyncConfigurationInProgress) { 221 OnSyncStateChanged_SyncConfigurationInProgress) {
222 CreateSyncObserver(kContinueUrl); 222 CreateSyncObserver(kContinueUrl);
223 sync_service_->set_first_setup_in_progress(true); 223 sync_service_->set_first_setup_in_progress(true);
224 sync_service_->set_sync_active(false); 224 sync_service_->set_sync_active(false);
225 225
226 EXPECT_CALL(*web_contents_observer_, 226 EXPECT_CALL(*web_contents_observer_,
227 AboutToNavigateRenderFrame(_, _)).Times(0); 227 DidStartNavigationToPendingEntry(_, _)).Times(0);
228 sync_service_->NotifyObservers(); 228 sync_service_->NotifyObservers();
229 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL()); 229 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL());
230 230
231 // Trigger an event to force state to be cleaned up. 231 // Trigger an event to force state to be cleaned up.
232 SetContents(NULL); 232 SetContents(NULL);
233 } 233 }
234 234
235 // Verify that if the continue_url is to the settings page, no navigation is 235 // Verify that if the continue_url is to the settings page, no navigation is
236 // triggered, since it would be redundant. 236 // triggered, since it would be redundant.
237 TEST_F(OneClickSigninSyncObserverTest, 237 TEST_F(OneClickSigninSyncObserverTest,
238 OnSyncStateChanged_SyncConfiguredSuccessfully_SourceIsSettings) { 238 OnSyncStateChanged_SyncConfiguredSuccessfully_SourceIsSettings) {
239 GURL continue_url = signin::GetPromoURL( 239 GURL continue_url = signin::GetPromoURL(
240 signin_metrics::SOURCE_SETTINGS, false); 240 signin_metrics::SOURCE_SETTINGS, false);
241 CreateSyncObserver(continue_url.spec()); 241 CreateSyncObserver(continue_url.spec());
242 sync_service_->set_first_setup_in_progress(false); 242 sync_service_->set_first_setup_in_progress(false);
243 sync_service_->set_sync_active(true); 243 sync_service_->set_sync_active(true);
244 244
245 EXPECT_CALL(*web_contents_observer_, 245 EXPECT_CALL(*web_contents_observer_,
246 AboutToNavigateRenderFrame(_, _)).Times(0); 246 DidStartNavigationToPendingEntry(_, _)).Times(0);
247 sync_service_->NotifyObservers(); 247 sync_service_->NotifyObservers();
248 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL()); 248 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL());
249 } 249 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_ui_bindings.cc ('k') | content/browser/devtools/protocol/devtools_protocol_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698