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/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/content_settings/cookie_settings.h" | 8 #include "chrome/browser/content_settings/cookie_settings.h" |
9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 9 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
10 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 10 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/browser/sync/profile_sync_service_mock.h" | 21 #include "chrome/browser/sync/profile_sync_service_mock.h" |
22 #include "chrome/browser/sync/test_profile_sync_service.h" | 22 #include "chrome/browser/sync/test_profile_sync_service.h" |
23 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 23 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
26 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
27 #include "chrome/test/base/testing_pref_service_syncable.h" | 27 #include "chrome/test/base/testing_pref_service_syncable.h" |
28 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
29 #include "chrome/test/base/testing_profile_manager.h" | 29 #include "chrome/test/base/testing_profile_manager.h" |
30 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
| 31 #include "content/public/browser/navigation_details.h" |
31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/common/frame_navigate_params.h" |
32 #include "content/public/common/password_form.h" | 34 #include "content/public/common/password_form.h" |
33 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
34 #include "content/public/test/mock_render_process_host.h" | 36 #include "content/public/test/mock_render_process_host.h" |
35 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
36 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
38 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
39 | 41 |
40 using ::testing::_; | 42 using ::testing::_; |
41 using ::testing::AtLeast; | 43 using ::testing::AtLeast; |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 SubmitGAIAPassword(helper); | 665 SubmitGAIAPassword(helper); |
664 | 666 |
665 NavigateAndCommit(GURL("https://chrome.google.com/webstore?source=3")); | 667 NavigateAndCommit(GURL("https://chrome.google.com/webstore?source=3")); |
666 helper->DidStopLoading(rvh()); | 668 helper->DidStopLoading(rvh()); |
667 | 669 |
668 helper->OnStateChanged(); | 670 helper->OnStateChanged(); |
669 EXPECT_EQ(GURL(continueUrl), contents->GetURL()); | 671 EXPECT_EQ(GURL(continueUrl), contents->GetURL()); |
670 EXPECT_EQ("user@gmail.com", signin_manager_->GetAuthenticatedUsername()); | 672 EXPECT_EQ("user@gmail.com", signin_manager_->GetAuthenticatedUsername()); |
671 } | 673 } |
672 | 674 |
| 675 // Checks that the state of OneClickSigninHelper is cleaned when there is a |
| 676 // navigation away from the sign in flow that is not triggered by the |
| 677 // web contents. |
| 678 TEST_F(OneClickSigninHelperTest, CleanTransientStateOnNavigate) { |
| 679 content::WebContents* contents = web_contents(); |
| 680 |
| 681 OneClickSigninHelper::CreateForWebContents(contents); |
| 682 OneClickSigninHelper* helper = |
| 683 OneClickSigninHelper::FromWebContents(contents); |
| 684 helper->SetDoNotClearPendingEmailForTesting(); |
| 685 helper->auto_accept_ = OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT; |
| 686 |
| 687 content::LoadCommittedDetails details; |
| 688 content::FrameNavigateParams params; |
| 689 params.url = GURL("http://crbug.com"); |
| 690 params.transition = content::PAGE_TRANSITION_TYPED; |
| 691 helper->DidNavigateMainFrame(details, params); |
| 692 |
| 693 EXPECT_EQ(OneClickSigninHelper::AUTO_ACCEPT_NONE, helper->auto_accept_); |
| 694 } |
| 695 |
673 // I/O thread tests | 696 // I/O thread tests |
674 | 697 |
675 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) { | 698 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) { |
676 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); | 699 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); |
677 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 700 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
678 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 701 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
679 valid_gaia_url_, std::string(), &request_, io_data.get())); | 702 valid_gaia_url_, std::string(), &request_, io_data.get())); |
680 } | 703 } |
681 | 704 |
682 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) { | 705 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); | 842 prefs::kSigninAllowed, base::Value::CreateBooleanValue(true)); |
820 | 843 |
821 // Simulate a policy disabling sync by writing kSyncManaged directly. | 844 // Simulate a policy disabling sync by writing kSyncManaged directly. |
822 // We should still offer to sign in the browser. | 845 // We should still offer to sign in the browser. |
823 profile()->GetTestingPrefService()->SetManagedPref( | 846 profile()->GetTestingPrefService()->SetManagedPref( |
824 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); | 847 prefs::kSyncManaged, base::Value::CreateBooleanValue(true)); |
825 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 848 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
826 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 849 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
827 valid_gaia_url_, std::string(), &request_, io_data.get())); | 850 valid_gaia_url_, std::string(), &request_, io_data.get())); |
828 } | 851 } |
OLD | NEW |