| OLD | NEW |
| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/browser/signin/signin_promo.h" | 17 #include "chrome/browser/signin/signin_promo.h" |
| 18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 19 #include "chrome/browser/sync/profile_sync_test_util.h" | 19 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/browser_sync/browser/test_profile_sync_service.h" | 22 #include "components/browser_sync/browser/test_profile_sync_service.h" |
| 23 #include "components/signin/core/browser/signin_manager.h" | 23 #include "components/signin/core/browser/signin_manager.h" |
| 24 #include "components/sync/driver/startup_controller.h" | 24 #include "components/sync/driver/startup_controller.h" |
| 25 #include "content/public/browser/reload_type.h" |
| 25 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 31 |
| 31 using testing::_; | 32 using testing::_; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 const char kContinueUrl[] = "https://www.example.com/"; | 36 const char kContinueUrl[] = "https://www.example.com/"; |
| 36 | 37 |
| 37 class MockWebContentsObserver : public content::WebContentsObserver { | 38 class MockWebContentsObserver : public content::WebContentsObserver { |
| 38 public: | 39 public: |
| 39 explicit MockWebContentsObserver(content::WebContents* web_contents) | 40 explicit MockWebContentsObserver(content::WebContents* web_contents) |
| 40 : content::WebContentsObserver(web_contents) {} | 41 : content::WebContentsObserver(web_contents) {} |
| 41 virtual ~MockWebContentsObserver() {} | 42 virtual ~MockWebContentsObserver() {} |
| 42 | 43 |
| 43 // A hook to verify that the OneClickSigninSyncObserver initiated a redirect | 44 // A hook to verify that the OneClickSigninSyncObserver initiated a redirect |
| 44 // to the continue URL. Navigations in unit_tests never complete, but a | 45 // to the continue URL. Navigations in unit_tests never complete, but a |
| 45 // navigation start is a sufficient signal for the purposes of this test. | 46 // navigation start is a sufficient signal for the purposes of this test. |
| 46 // Listening for this call also has the advantage of being synchronous. | 47 // Listening for this call also has the advantage of being synchronous. |
| 47 MOCK_METHOD2(DidStartNavigationToPendingEntry, | 48 MOCK_METHOD2(DidStartNavigationToPendingEntry, |
| 48 void(const GURL&, content::NavigationController::ReloadType)); | 49 void(const GURL&, content::ReloadType)); |
| 49 }; | 50 }; |
| 50 | 51 |
| 51 class OneClickTestProfileSyncService : public TestProfileSyncService { | 52 class OneClickTestProfileSyncService : public TestProfileSyncService { |
| 52 public: | 53 public: |
| 53 ~OneClickTestProfileSyncService() override {} | 54 ~OneClickTestProfileSyncService() override {} |
| 54 | 55 |
| 55 // Helper routine to be used in conjunction with | 56 // Helper routine to be used in conjunction with |
| 56 // BrowserContextKeyedServiceFactory::SetTestingFactory(). | 57 // BrowserContextKeyedServiceFactory::SetTestingFactory(). |
| 57 static std::unique_ptr<KeyedService> Build(content::BrowserContext* profile) { | 58 static std::unique_ptr<KeyedService> Build(content::BrowserContext* profile) { |
| 58 return base::WrapUnique(new OneClickTestProfileSyncService( | 59 return base::WrapUnique(new OneClickTestProfileSyncService( |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, false); | 250 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, false); |
| 250 CreateSyncObserver(continue_url.spec()); | 251 CreateSyncObserver(continue_url.spec()); |
| 251 sync_service_->set_first_setup_in_progress(false); | 252 sync_service_->set_first_setup_in_progress(false); |
| 252 sync_service_->set_sync_active(true); | 253 sync_service_->set_sync_active(true); |
| 253 | 254 |
| 254 EXPECT_CALL(*web_contents_observer_, | 255 EXPECT_CALL(*web_contents_observer_, |
| 255 DidStartNavigationToPendingEntry(_, _)).Times(0); | 256 DidStartNavigationToPendingEntry(_, _)).Times(0); |
| 256 sync_service_->NotifyObservers(); | 257 sync_service_->NotifyObservers(); |
| 257 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL()); | 258 EXPECT_NE(GURL(kContinueUrl), web_contents()->GetVisibleURL()); |
| 258 } | 259 } |
| OLD | NEW |