OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/passwords/password_controller.h" | 5 #import "ios/chrome/browser/passwords/password_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 base::WrapUnique(new syncable_prefs::TestingPrefServiceSyncable); | 65 base::WrapUnique(new syncable_prefs::TestingPrefServiceSyncable); |
66 pref_service->registry()->RegisterBooleanPref( | 66 pref_service->registry()->RegisterBooleanPref( |
67 password_manager::prefs::kPasswordManagerSavingEnabled, true); | 67 password_manager::prefs::kPasswordManagerSavingEnabled, true); |
68 builder.SetPrefService(std::move(pref_service)); | 68 builder.SetPrefService(std::move(pref_service)); |
69 std::unique_ptr<TestChromeBrowserState> browser_state(builder.Build()); | 69 std::unique_ptr<TestChromeBrowserState> browser_state(builder.Build()); |
70 MockWebState web_state; | 70 MockWebState web_state; |
71 ON_CALL(web_state, GetBrowserState()) | 71 ON_CALL(web_state, GetBrowserState()) |
72 .WillByDefault(testing::Return(browser_state.get())); | 72 .WillByDefault(testing::Return(browser_state.get())); |
73 auto client = base::WrapUnique(new MockPasswordManagerClient); | 73 auto client = base::WrapUnique(new MockPasswordManagerClient); |
74 MockPasswordManagerClient* weak_client = client.get(); | 74 MockPasswordManagerClient* weak_client = client.get(); |
75 base::scoped_nsobject<PasswordController> passwordController = | 75 base::scoped_nsobject<PasswordController> passwordController( |
76 [[PasswordController alloc] initWithWebState:&web_state | 76 [[PasswordController alloc] initWithWebState:&web_state |
77 passwordsUiDelegate:nil | 77 passwordsUiDelegate:nil |
78 client:std::move(client)]; | 78 client:std::move(client)]); |
79 | 79 |
80 // Use a mock LogManager to detect that OnPasswordFormsRendered has been | 80 // Use a mock LogManager to detect that OnPasswordFormsRendered has been |
81 // called. TODO(crbug.com/598672): this is a hack, we should modularize the | 81 // called. TODO(crbug.com/598672): this is a hack, we should modularize the |
82 // code better to allow proper unit-testing. | 82 // code better to allow proper unit-testing. |
83 MockLogManager log_manager; | 83 MockLogManager log_manager; |
84 EXPECT_CALL(log_manager, IsLoggingActive()).WillRepeatedly(Return(true)); | 84 EXPECT_CALL(log_manager, IsLoggingActive()).WillRepeatedly(Return(true)); |
85 EXPECT_CALL(log_manager, | 85 EXPECT_CALL(log_manager, |
86 LogSavePasswordProgress( | 86 LogSavePasswordProgress( |
87 "Message: \"PasswordManager::OnPasswordFormsRendered\"\n")); | 87 "Message: \"PasswordManager::OnPasswordFormsRendered\"\n")); |
88 EXPECT_CALL(log_manager, | 88 EXPECT_CALL(log_manager, |
89 LogSavePasswordProgress(testing::Ne( | 89 LogSavePasswordProgress(testing::Ne( |
90 "Message: \"PasswordManager::OnPasswordFormsRendered\"\n"))) | 90 "Message: \"PasswordManager::OnPasswordFormsRendered\"\n"))) |
91 .Times(testing::AnyNumber()); | 91 .Times(testing::AnyNumber()); |
92 EXPECT_CALL(*weak_client, GetLogManager()) | 92 EXPECT_CALL(*weak_client, GetLogManager()) |
93 .WillRepeatedly(Return(&log_manager)); | 93 .WillRepeatedly(Return(&log_manager)); |
94 | 94 |
95 web_state.SetContentIsHTML(false); | 95 web_state.SetContentIsHTML(false); |
96 web_state.SetCurrentURL(GURL("https://example.com")); | 96 web_state.SetCurrentURL(GURL("https://example.com")); |
97 [passwordController webStateDidLoadPage:&web_state]; | 97 [passwordController webStateDidLoadPage:&web_state]; |
98 } | 98 } |
OLD | NEW |