| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | |
| 8 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 9 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 8 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
| 10 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 9 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 11 #import "ios/chrome/browser/passwords/password_controller.h" | 10 #import "ios/chrome/browser/passwords/password_controller.h" |
| 12 #import "ios/web/public/test/test_web_state.h" | 11 #import "ios/web/public/test/test_web_state.h" |
| 13 #import "ios/web/public/test/web_test_with_web_state.h" | 12 #import "ios/web/public/test/web_test_with_web_state.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 18 class IncognitoPasswordManagerClient | 21 class IncognitoPasswordManagerClient |
| 19 : public password_manager::StubPasswordManagerClient { | 22 : public password_manager::StubPasswordManagerClient { |
| 20 public: | 23 public: |
| 21 bool IsOffTheRecord() const override { return true; } | 24 bool IsOffTheRecord() const override { return true; } |
| 22 }; | 25 }; |
| 23 | 26 |
| 24 } // namespace | 27 } // namespace |
| 25 | 28 |
| 26 class OffTheRecordWebState : public web::TestWebState { | 29 class OffTheRecordWebState : public web::TestWebState { |
| 27 public: | 30 public: |
| 28 OffTheRecordWebState() { | 31 OffTheRecordWebState() { |
| 29 TestChromeBrowserState::Builder test_cbs_builder; | 32 TestChromeBrowserState::Builder test_cbs_builder; |
| 30 chrome_browser_state_ = test_cbs_builder.Build(); | 33 chrome_browser_state_ = test_cbs_builder.Build(); |
| 31 } | 34 } |
| 32 | 35 |
| 33 web::BrowserState* GetBrowserState() const override { | 36 web::BrowserState* GetBrowserState() const override { |
| 34 return chrome_browser_state_->GetOffTheRecordChromeBrowserState(); | 37 return chrome_browser_state_->GetOffTheRecordChromeBrowserState(); |
| 35 } | 38 } |
| 36 | 39 |
| 37 private: | 40 private: |
| 38 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 41 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 class PasswordControllerOffTheRecordTest : public web::WebTestWithWebState { | 44 class PasswordControllerOffTheRecordTest : public web::WebTestWithWebState { |
| 42 public: | 45 public: |
| 43 void SetUp() override { | 46 void SetUp() override { |
| 44 web::WebTestWithWebState::SetUp(); | 47 web::WebTestWithWebState::SetUp(); |
| 45 password_controller_.reset([[PasswordController alloc] | 48 password_controller_ = [[PasswordController alloc] |
| 46 initWithWebState:&off_the_record_web_state_ | 49 initWithWebState:&off_the_record_web_state_ |
| 47 passwordsUiDelegate:nil | 50 passwordsUiDelegate:nil |
| 48 client:base::MakeUnique< | 51 client:base::MakeUnique<IncognitoPasswordManagerClient>()]; |
| 49 IncognitoPasswordManagerClient>()]); | |
| 50 } | 52 } |
| 51 | 53 |
| 52 void TearDown() override { | 54 void TearDown() override { |
| 53 [password_controller_ detach]; | 55 [password_controller_ detach]; |
| 54 web::WebTestWithWebState::TearDown(); | 56 web::WebTestWithWebState::TearDown(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 protected: | 59 protected: |
| 58 OffTheRecordWebState off_the_record_web_state_; | 60 OffTheRecordWebState off_the_record_web_state_; |
| 59 base::scoped_nsobject<PasswordController> password_controller_; | 61 PasswordController* password_controller_; |
| 60 }; | 62 }; |
| 61 | 63 |
| 62 // Check that if the PasswordController is told (by the PasswordManagerClient) | 64 // Check that if the PasswordController is told (by the PasswordManagerClient) |
| 63 // that this is Incognito, it won't enable password generation. | 65 // that this is Incognito, it won't enable password generation. |
| 64 TEST_F(PasswordControllerOffTheRecordTest, PasswordGenerationDisabled) { | 66 TEST_F(PasswordControllerOffTheRecordTest, PasswordGenerationDisabled) { |
| 65 EXPECT_FALSE([this->password_controller_ passwordGenerationManager]); | 67 EXPECT_FALSE([this->password_controller_ passwordGenerationManager]); |
| 66 } | 68 } |
| OLD | NEW |