Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_settings_backend.h" | |
| 11 #include "chrome/browser/extensions/extension_settings_sync_util.h" | 10 #include "chrome/browser/extensions/extension_settings_sync_util.h" |
| 12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sync/api/sync_change.h" | 13 #include "chrome/browser/sync/api/sync_change.h" |
| 15 #include "chrome/browser/sync/api/sync_change_processor.h" | 14 #include "chrome/browser/sync/api/sync_change_processor.h" |
| 16 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 50 } | 49 } |
| 51 | 50 |
| 52 void FinalReplyWhenSatisfied( | 51 void FinalReplyWhenSatisfied( |
| 53 const std::string& normal_action, | 52 const std::string& normal_action, |
| 54 const std::string& incognito_action) { | 53 const std::string& incognito_action) { |
| 55 MaybeLoadAndReplyWhenSatisfied(normal_action, incognito_action, NULL, true); | 54 MaybeLoadAndReplyWhenSatisfied(normal_action, incognito_action, NULL, true); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void InitSync(SyncChangeProcessor* sync_processor) { | 57 void InitSync(SyncChangeProcessor* sync_processor) { |
| 59 browser()->profile()->GetExtensionService()-> | 58 browser()->profile()->GetExtensionService()-> |
| 60 extension_settings_frontend()->RunWithBackend(base::Bind( | 59 extension_settings_frontend()->RunWithSyncableService( |
| 61 &ExtensionSettingsApiTest::InitSyncWithBackend, | 60 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS. |
|
akalin
2011/10/28 06:04:54
Do you know about parametrized tests? http://code.
not at google - send to devlin
2011/10/31 00:02:23
Yep I know about parameterised tests (the Extensio
| |
| 62 this, | 61 syncable::EXTENSION_SETTINGS, |
| 63 sync_processor)); | 62 base::Bind( |
| 63 &ExtensionSettingsApiTest::InitSyncWithSyncableService, | |
| 64 this, | |
| 65 sync_processor)); | |
| 64 MessageLoop::current()->RunAllPending(); | 66 MessageLoop::current()->RunAllPending(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void SendChanges(const SyncChangeList& change_list) { | 69 void SendChanges(const SyncChangeList& change_list) { |
| 68 browser()->profile()->GetExtensionService()-> | 70 browser()->profile()->GetExtensionService()-> |
| 69 extension_settings_frontend()->RunWithBackend(base::Bind( | 71 extension_settings_frontend()->RunWithSyncableService( |
| 70 &ExtensionSettingsApiTest::SendChangesToBackend, | 72 // TODO(kalman): test both EXTENSION_SETTINGS and APP_SETTINGS. |
| 71 this, | 73 syncable::EXTENSION_SETTINGS, |
| 72 change_list)); | 74 base::Bind( |
| 75 &ExtensionSettingsApiTest::SendChangesToSyncableService, | |
| 76 this, | |
| 77 change_list)); | |
| 73 MessageLoop::current()->RunAllPending(); | 78 MessageLoop::current()->RunAllPending(); |
| 74 } | 79 } |
| 75 | 80 |
| 76 private: | 81 private: |
| 77 const Extension* MaybeLoadAndReplyWhenSatisfied( | 82 const Extension* MaybeLoadAndReplyWhenSatisfied( |
| 78 const std::string& normal_action, | 83 const std::string& normal_action, |
| 79 const std::string& incognito_action, | 84 const std::string& incognito_action, |
| 80 // May be NULL to imply not loading the extension. | 85 // May be NULL to imply not loading the extension. |
| 81 const std::string* extension_dir, | 86 const std::string* extension_dir, |
| 82 bool is_final_action) { | 87 bool is_final_action) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 102 | 107 |
| 103 std::string CreateMessage(const std::string& action, bool is_final_action) { | 108 std::string CreateMessage(const std::string& action, bool is_final_action) { |
| 104 scoped_ptr<DictionaryValue> message(new DictionaryValue()); | 109 scoped_ptr<DictionaryValue> message(new DictionaryValue()); |
| 105 message->SetString("action", action); | 110 message->SetString("action", action); |
| 106 message->SetBoolean("isFinalAction", is_final_action); | 111 message->SetBoolean("isFinalAction", is_final_action); |
| 107 std::string message_json; | 112 std::string message_json; |
| 108 base::JSONWriter::Write(message.get(), false, &message_json); | 113 base::JSONWriter::Write(message.get(), false, &message_json); |
| 109 return message_json; | 114 return message_json; |
| 110 } | 115 } |
| 111 | 116 |
| 112 void InitSyncWithBackend( | 117 void InitSyncWithSyncableService( |
| 113 SyncChangeProcessor* sync_processor, ExtensionSettingsBackend* backend) { | 118 SyncChangeProcessor* sync_processor, SyncableService* settings_service) { |
| 114 EXPECT_FALSE(backend->MergeDataAndStartSyncing( | 119 EXPECT_FALSE(settings_service->MergeDataAndStartSyncing( |
| 115 syncable::EXTENSION_SETTINGS, | 120 syncable::EXTENSION_SETTINGS, |
| 116 SyncDataList(), | 121 SyncDataList(), |
| 117 sync_processor).IsSet()); | 122 sync_processor).IsSet()); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void SendChangesToBackend( | 125 void SendChangesToSyncableService( |
| 121 const SyncChangeList& change_list, ExtensionSettingsBackend* backend) { | 126 const SyncChangeList& change_list, SyncableService* settings_service) { |
| 122 EXPECT_FALSE(backend->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | 127 EXPECT_FALSE( |
| 128 settings_service->ProcessSyncChanges(FROM_HERE, change_list).IsSet()); | |
| 123 } | 129 } |
| 124 }; | 130 }; |
| 125 | 131 |
| 126 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SimpleTest) { | 132 IN_PROC_BROWSER_TEST_F(ExtensionSettingsApiTest, SimpleTest) { |
| 127 CommandLine::ForCurrentProcess()->AppendSwitch( | 133 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 128 switches::kEnableExperimentalExtensionApis); | 134 switches::kEnableExperimentalExtensionApis); |
| 129 ASSERT_TRUE(RunExtensionTest("settings/simple_test")) << message_; | 135 ASSERT_TRUE(RunExtensionTest("settings/simple_test")) << message_; |
| 130 } | 136 } |
| 131 | 137 |
| 132 // Structure of this test taken from IncognitoSplitMode. | 138 // Structure of this test taken from IncognitoSplitMode. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 sync_changes.push_back(extension_settings_sync_util::CreateDelete( | 225 sync_changes.push_back(extension_settings_sync_util::CreateDelete( |
| 220 extension_id, "foo")); | 226 extension_id, "foo")); |
| 221 SendChanges(sync_changes); | 227 SendChanges(sync_changes); |
| 222 | 228 |
| 223 FinalReplyWhenSatisfied( | 229 FinalReplyWhenSatisfied( |
| 224 "assertDeleteFooNotification", "assertDeleteFooNotification"); | 230 "assertDeleteFooNotification", "assertDeleteFooNotification"); |
| 225 | 231 |
| 226 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 232 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 227 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); | 233 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); |
| 228 } | 234 } |
| OLD | NEW |