| 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 "chrome/browser/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); | 140 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| 144 } // namespace | 144 } // namespace |
| 145 | 145 |
| 146 // Test instance of WebUI that tracks the data passed to | 146 // Test instance of WebUI that tracks the data passed to |
| 147 // CallJavascriptFunction(). | 147 // CallJavascriptFunction(). |
| 148 class TestWebUI : public content::WebUI { | 148 class TestWebUI : public content::WebUI { |
| 149 public: | 149 public: |
| 150 virtual ~TestWebUI() { | 150 ~TestWebUI() override { ClearTrackedCalls(); } |
| 151 ClearTrackedCalls(); | |
| 152 } | |
| 153 | 151 |
| 154 void ClearTrackedCalls() { | 152 void ClearTrackedCalls() { |
| 155 // Manually free the arguments stored in CallData, since there's no good | 153 // Manually free the arguments stored in CallData, since there's no good |
| 156 // way to use a self-freeing reference like scoped_ptr in a std::vector. | 154 // way to use a self-freeing reference like scoped_ptr in a std::vector. |
| 157 for (std::vector<CallData>::iterator i = call_data_.begin(); | 155 for (std::vector<CallData>::iterator i = call_data_.begin(); |
| 158 i != call_data_.end(); | 156 i != call_data_.end(); |
| 159 ++i) { | 157 ++i) { |
| 160 delete i->arg1; | 158 delete i->arg1; |
| 161 delete i->arg2; | 159 delete i->arg2; |
| 162 } | 160 } |
| 163 call_data_.clear(); | 161 call_data_.clear(); |
| 164 } | 162 } |
| 165 | 163 |
| 166 virtual void CallJavascriptFunction(const std::string& function_name) | 164 void CallJavascriptFunction(const std::string& function_name) override { |
| 167 override { | |
| 168 call_data_.push_back(CallData()); | 165 call_data_.push_back(CallData()); |
| 169 call_data_.back().function_name = function_name; | 166 call_data_.back().function_name = function_name; |
| 170 } | 167 } |
| 171 | 168 |
| 172 virtual void CallJavascriptFunction(const std::string& function_name, | 169 void CallJavascriptFunction(const std::string& function_name, |
| 173 const base::Value& arg1) override { | 170 const base::Value& arg1) override { |
| 174 call_data_.push_back(CallData()); | 171 call_data_.push_back(CallData()); |
| 175 call_data_.back().function_name = function_name; | 172 call_data_.back().function_name = function_name; |
| 176 call_data_.back().arg1 = arg1.DeepCopy(); | 173 call_data_.back().arg1 = arg1.DeepCopy(); |
| 177 } | 174 } |
| 178 | 175 |
| 179 virtual void CallJavascriptFunction(const std::string& function_name, | 176 void CallJavascriptFunction(const std::string& function_name, |
| 180 const base::Value& arg1, | 177 const base::Value& arg1, |
| 181 const base::Value& arg2) override { | 178 const base::Value& arg2) override { |
| 182 call_data_.push_back(CallData()); | 179 call_data_.push_back(CallData()); |
| 183 call_data_.back().function_name = function_name; | 180 call_data_.back().function_name = function_name; |
| 184 call_data_.back().arg1 = arg1.DeepCopy(); | 181 call_data_.back().arg1 = arg1.DeepCopy(); |
| 185 call_data_.back().arg2 = arg2.DeepCopy(); | 182 call_data_.back().arg2 = arg2.DeepCopy(); |
| 186 } | 183 } |
| 187 | 184 |
| 188 virtual content::WebContents* GetWebContents() const override { | 185 content::WebContents* GetWebContents() const override { return NULL; } |
| 189 return NULL; | 186 content::WebUIController* GetController() const override { return NULL; } |
| 190 } | 187 void SetController(content::WebUIController* controller) override {} |
| 191 virtual content::WebUIController* GetController() const override { | 188 float GetDeviceScaleFactor() const override { return 1.0f; } |
| 192 return NULL; | 189 const base::string16& GetOverriddenTitle() const override { |
| 193 } | |
| 194 virtual void SetController(content::WebUIController* controller) override {} | |
| 195 virtual float GetDeviceScaleFactor() const override { | |
| 196 return 1.0f; | |
| 197 } | |
| 198 virtual const base::string16& GetOverriddenTitle() const override { | |
| 199 return temp_string_; | 190 return temp_string_; |
| 200 } | 191 } |
| 201 virtual void OverrideTitle(const base::string16& title) override {} | 192 void OverrideTitle(const base::string16& title) override {} |
| 202 virtual ui::PageTransition GetLinkTransitionType() const override { | 193 ui::PageTransition GetLinkTransitionType() const override { |
| 203 return ui::PAGE_TRANSITION_LINK; | 194 return ui::PAGE_TRANSITION_LINK; |
| 204 } | 195 } |
| 205 virtual void SetLinkTransitionType(ui::PageTransition type) override {} | 196 void SetLinkTransitionType(ui::PageTransition type) override {} |
| 206 virtual int GetBindings() const override { | 197 int GetBindings() const override { return 0; } |
| 207 return 0; | 198 void SetBindings(int bindings) override {} |
| 208 } | 199 void OverrideJavaScriptFrame(const std::string& frame_name) override {} |
| 209 virtual void SetBindings(int bindings) override {} | 200 void AddMessageHandler(content::WebUIMessageHandler* handler) override {} |
| 210 virtual void OverrideJavaScriptFrame( | 201 void RegisterMessageCallback(const std::string& message, |
| 211 const std::string& frame_name) override {} | 202 const MessageCallback& callback) override {} |
| 212 virtual void AddMessageHandler( | 203 void ProcessWebUIMessage(const GURL& source_url, |
| 213 content::WebUIMessageHandler* handler) override {} | 204 const std::string& message, |
| 214 virtual void RegisterMessageCallback( | 205 const base::ListValue& args) override {} |
| 215 const std::string& message, | 206 void CallJavascriptFunction(const std::string& function_name, |
| 216 const MessageCallback& callback) override {} | 207 const base::Value& arg1, |
| 217 virtual void ProcessWebUIMessage(const GURL& source_url, | 208 const base::Value& arg2, |
| 218 const std::string& message, | 209 const base::Value& arg3) override {} |
| 219 const base::ListValue& args) override {} | 210 void CallJavascriptFunction(const std::string& function_name, |
| 220 virtual void CallJavascriptFunction(const std::string& function_name, | 211 const base::Value& arg1, |
| 221 const base::Value& arg1, | 212 const base::Value& arg2, |
| 222 const base::Value& arg2, | 213 const base::Value& arg3, |
| 223 const base::Value& arg3) override {} | 214 const base::Value& arg4) override {} |
| 224 virtual void CallJavascriptFunction(const std::string& function_name, | 215 void CallJavascriptFunction( |
| 225 const base::Value& arg1, | |
| 226 const base::Value& arg2, | |
| 227 const base::Value& arg3, | |
| 228 const base::Value& arg4) override {} | |
| 229 virtual void CallJavascriptFunction( | |
| 230 const std::string& function_name, | 216 const std::string& function_name, |
| 231 const std::vector<const base::Value*>& args) override {} | 217 const std::vector<const base::Value*>& args) override {} |
| 232 | 218 |
| 233 class CallData { | 219 class CallData { |
| 234 public: | 220 public: |
| 235 CallData() : arg1(NULL), arg2(NULL) {} | 221 CallData() : arg1(NULL), arg2(NULL) {} |
| 236 std::string function_name; | 222 std::string function_name; |
| 237 base::Value* arg1; | 223 base::Value* arg1; |
| 238 base::Value* arg2; | 224 base::Value* arg2; |
| 239 }; | 225 }; |
| 240 const std::vector<CallData>& call_data() { return call_data_; } | 226 const std::vector<CallData>& call_data() { return call_data_; } |
| 241 private: | 227 private: |
| 242 std::vector<CallData> call_data_; | 228 std::vector<CallData> call_data_; |
| 243 base::string16 temp_string_; | 229 base::string16 temp_string_; |
| 244 }; | 230 }; |
| 245 | 231 |
| 246 class TestingSyncSetupHandler : public SyncSetupHandler { | 232 class TestingSyncSetupHandler : public SyncSetupHandler { |
| 247 public: | 233 public: |
| 248 TestingSyncSetupHandler(content::WebUI* web_ui, Profile* profile) | 234 TestingSyncSetupHandler(content::WebUI* web_ui, Profile* profile) |
| 249 : SyncSetupHandler(NULL), | 235 : SyncSetupHandler(NULL), |
| 250 profile_(profile) { | 236 profile_(profile) { |
| 251 set_web_ui(web_ui); | 237 set_web_ui(web_ui); |
| 252 } | 238 } |
| 253 virtual ~TestingSyncSetupHandler() { | 239 ~TestingSyncSetupHandler() override { set_web_ui(NULL); } |
| 254 set_web_ui(NULL); | |
| 255 } | |
| 256 | 240 |
| 257 virtual void FocusUI() override {} | 241 void FocusUI() override {} |
| 258 | 242 |
| 259 virtual Profile* GetProfile() const override { return profile_; } | 243 Profile* GetProfile() const override { return profile_; } |
| 260 | 244 |
| 261 using SyncSetupHandler::is_configuring_sync; | 245 using SyncSetupHandler::is_configuring_sync; |
| 262 | 246 |
| 263 private: | 247 private: |
| 264 #if !defined(OS_CHROMEOS) | 248 #if !defined(OS_CHROMEOS) |
| 265 virtual void DisplayGaiaLoginInNewTabOrWindow() override {} | 249 void DisplayGaiaLoginInNewTabOrWindow() override {} |
| 266 #endif | 250 #endif |
| 267 | 251 |
| 268 // Weak pointer to parent profile. | 252 // Weak pointer to parent profile. |
| 269 Profile* profile_; | 253 Profile* profile_; |
| 270 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler); | 254 DISALLOW_COPY_AND_ASSIGN(TestingSyncSetupHandler); |
| 271 }; | 255 }; |
| 272 | 256 |
| 273 // The boolean parameter indicates whether the test is run with ClientOAuth | 257 // The boolean parameter indicates whether the test is run with ClientOAuth |
| 274 // or not. The test parameter is a bool: whether or not to test with/ | 258 // or not. The test parameter is a bool: whether or not to test with/ |
| 275 // /ClientLogin enabled or not. | 259 // /ClientLogin enabled or not. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 content::TestBrowserThreadBundle thread_bundle_; | 364 content::TestBrowserThreadBundle thread_bundle_; |
| 381 scoped_ptr<Profile> profile_; | 365 scoped_ptr<Profile> profile_; |
| 382 ProfileSyncServiceMock* mock_pss_; | 366 ProfileSyncServiceMock* mock_pss_; |
| 383 GoogleServiceAuthError error_; | 367 GoogleServiceAuthError error_; |
| 384 SigninManagerBase* mock_signin_; | 368 SigninManagerBase* mock_signin_; |
| 385 TestWebUI web_ui_; | 369 TestWebUI web_ui_; |
| 386 scoped_ptr<TestingSyncSetupHandler> handler_; | 370 scoped_ptr<TestingSyncSetupHandler> handler_; |
| 387 }; | 371 }; |
| 388 | 372 |
| 389 class SyncSetupHandlerFirstSigninTest : public SyncSetupHandlerTest { | 373 class SyncSetupHandlerFirstSigninTest : public SyncSetupHandlerTest { |
| 390 virtual std::string GetTestUser() override { return std::string(); } | 374 std::string GetTestUser() override { return std::string(); } |
| 391 }; | 375 }; |
| 392 | 376 |
| 393 TEST_F(SyncSetupHandlerTest, Basic) { | 377 TEST_F(SyncSetupHandlerTest, Basic) { |
| 394 } | 378 } |
| 395 | 379 |
| 396 #if !defined(OS_CHROMEOS) | 380 #if !defined(OS_CHROMEOS) |
| 397 TEST_F(SyncSetupHandlerFirstSigninTest, DisplayBasicLogin) { | 381 TEST_F(SyncSetupHandlerFirstSigninTest, DisplayBasicLogin) { |
| 398 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) | 382 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) |
| 399 .WillRepeatedly(Return(false)); | 383 .WillRepeatedly(Return(false)); |
| 400 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) | 384 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 | 1035 |
| 1052 // This should display the sync setup dialog (not login). | 1036 // This should display the sync setup dialog (not login). |
| 1053 handler_->OpenSyncSetup(); | 1037 handler_->OpenSyncSetup(); |
| 1054 | 1038 |
| 1055 ExpectConfig(); | 1039 ExpectConfig(); |
| 1056 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 1040 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 1057 base::DictionaryValue* dictionary; | 1041 base::DictionaryValue* dictionary; |
| 1058 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 1042 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 1059 CheckBool(dictionary, "encryptAllData", true); | 1043 CheckBool(dictionary, "encryptAllData", true); |
| 1060 } | 1044 } |
| OLD | NEW |