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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/content_settings/cookie_settings.h" | 7 #include "chrome/browser/content_settings/cookie_settings.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 9 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
12 #include "chrome/browser/profiles/profile_io_data.h" | 12 #include "chrome/browser/profiles/profile_io_data.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
15 #include "chrome/browser/signin/signin_manager_fake.h" | 15 #include "chrome/browser/signin/signin_manager_fake.h" |
16 #include "chrome/browser/signin/signin_names_io_thread.h" | 16 #include "chrome/browser/signin/signin_names_io_thread.h" |
17 #include "chrome/browser/sync/profile_sync_service_mock.h" | 17 #include "chrome/browser/sync/profile_sync_service_mock.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/test_profile_sync_service.h" | 19 #include "chrome/browser/sync/test_profile_sync_service.h" |
20 #include "chrome/browser/ui/sync/one_click_signin_helper.h" | 20 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
24 #include "chrome/test/base/testing_pref_service.h" | 24 #include "chrome/test/base/testing_pref_service.h" |
25 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
26 #include "chrome/test/base/testing_profile_manager.h" | 26 #include "chrome/test/base/testing_profile_manager.h" |
27 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/test/mock_render_process_host.h" |
29 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
30 #include "content/public/test/test_renderer_host.h" | 31 #include "content/public/test/test_renderer_host.h" |
31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 | 34 |
34 using ::testing::_; | 35 using ::testing::_; |
35 using ::testing::Mock; | 36 using ::testing::Mock; |
36 using ::testing::Return; | 37 using ::testing::Return; |
37 using ::testing::ReturnRef; | 38 using ::testing::ReturnRef; |
38 using ::testing::Values; | 39 using ::testing::Values; |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 EXPECT_FALSE(OneClickSigninHelper::CanOffer( | 513 EXPECT_FALSE(OneClickSigninHelper::CanOffer( |
513 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, | 514 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_ALL, |
514 "user@gmail.com", &error_message_id)); | 515 "user@gmail.com", &error_message_id)); |
515 EXPECT_EQ(0, error_message_id); | 516 EXPECT_EQ(0, error_message_id); |
516 EXPECT_FALSE(OneClickSigninHelper::CanOffer( | 517 EXPECT_FALSE(OneClickSigninHelper::CanOffer( |
517 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY, | 518 web_contents(), OneClickSigninHelper::CAN_OFFER_FOR_INTERSTITAL_ONLY, |
518 "", &error_message_id)); | 519 "", &error_message_id)); |
519 EXPECT_EQ(0, error_message_id); | 520 EXPECT_EQ(0, error_message_id); |
520 } | 521 } |
521 | 522 |
| 523 // Should not crash if a helper instance is not associated with an incognito |
| 524 // web contents. |
| 525 TEST_F(OneClickSigninHelperTest, ShowInfoBarUIThreadIncognito) { |
| 526 CreateSigninManager(true, ""); |
| 527 OneClickSigninHelper* helper = |
| 528 OneClickSigninHelper::FromWebContents(web_contents()); |
| 529 EXPECT_EQ(NULL, helper); |
| 530 |
| 531 OneClickSigninHelper::ShowInfoBarUIThread("session_index", "email", |
| 532 OneClickSigninHelper::AUTO_ACCEPT, |
| 533 SyncPromoUI::SOURCE_UNKNOWN, |
| 534 process()->GetID(), |
| 535 rvh()->GetRoutingID()); |
| 536 } |
| 537 |
522 // I/O thread tests | 538 // I/O thread tests |
523 | 539 |
524 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) { | 540 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThread) { |
525 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); | 541 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); |
526 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, | 542 EXPECT_EQ(OneClickSigninHelper::CAN_OFFER, |
527 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 543 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
528 valid_gaia_url_, "", &request_, io_data.get())); | 544 valid_gaia_url_, "", &request_, io_data.get())); |
529 } | 545 } |
530 | 546 |
531 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) { | 547 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadIncognito) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 valid_gaia_url_, "", &request_, io_data.get())); | 654 valid_gaia_url_, "", &request_, io_data.get())); |
639 } | 655 } |
640 | 656 |
641 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadNoSigninCookies) { | 657 TEST_F(OneClickSigninHelperIOTest, CanOfferOnIOThreadNoSigninCookies) { |
642 AllowSigninCookies(false); | 658 AllowSigninCookies(false); |
643 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); | 659 scoped_ptr<TestProfileIOData> io_data(CreateTestProfileIOData(false)); |
644 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER, | 660 EXPECT_EQ(OneClickSigninHelper::DONT_OFFER, |
645 OneClickSigninHelper::CanOfferOnIOThreadImpl( | 661 OneClickSigninHelper::CanOfferOnIOThreadImpl( |
646 valid_gaia_url_, "", &request_, io_data.get())); | 662 valid_gaia_url_, "", &request_, io_data.get())); |
647 } | 663 } |
OLD | NEW |