Chromium Code Reviews| 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/extensions/extension_function_test_utils.h" | 5 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | |
| 12 #include "chrome/browser/extensions/extension_function.h" | 13 #include "chrome/browser/extensions/extension_function.h" |
| 13 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 14 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using content::WebContents; | 20 using content::WebContents; |
| 20 using extensions::Extension; | 21 using extensions::Extension; |
| 22 namespace keys = extensions::tabs_constants; | |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 class TestFunctionDispatcherDelegate | 26 class TestFunctionDispatcherDelegate |
| 25 : public ExtensionFunctionDispatcher::Delegate { | 27 : public ExtensionFunctionDispatcher::Delegate { |
| 26 public: | 28 public: |
| 27 explicit TestFunctionDispatcherDelegate(Browser* browser) : | 29 explicit TestFunctionDispatcherDelegate(Browser* browser) : |
| 28 browser_(browser) {} | 30 browser_(browser) {} |
| 29 virtual ~TestFunctionDispatcherDelegate() {} | 31 virtual ~TestFunctionDispatcherDelegate() {} |
| 30 | 32 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 EXPECT_EQ(base::Value::TYPE_LIST, val->GetType()); | 100 EXPECT_EQ(base::Value::TYPE_LIST, val->GetType()); |
| 99 return static_cast<base::ListValue*>(val); | 101 return static_cast<base::ListValue*>(val); |
| 100 } | 102 } |
| 101 | 103 |
| 102 scoped_refptr<Extension> CreateEmptyExtension() { | 104 scoped_refptr<Extension> CreateEmptyExtension() { |
| 103 return CreateEmptyExtensionWithLocation(Extension::INTERNAL); | 105 return CreateEmptyExtensionWithLocation(Extension::INTERNAL); |
| 104 } | 106 } |
| 105 | 107 |
| 106 scoped_refptr<Extension> CreateEmptyExtensionWithLocation( | 108 scoped_refptr<Extension> CreateEmptyExtensionWithLocation( |
| 107 Extension::Location location) { | 109 Extension::Location location) { |
| 110 scoped_ptr<base::DictionaryValue> test_extension_value( | |
| 111 ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}")); | |
| 112 return CreateExtension(location, test_extension_value.get()); | |
| 113 } | |
| 114 | |
| 115 scoped_refptr<Extension> CreateEmptyExtensionWithValue( | |
|
Aaron Boodman
2012/08/07 01:03:25
This should also just be called CreateExtension. I
SanjoyPal
2012/08/14 11:14:13
Done.
| |
| 116 base::DictionaryValue* test_extension_value) { | |
| 117 return CreateExtension(Extension::INTERNAL, test_extension_value); | |
| 118 } | |
| 119 | |
| 120 scoped_refptr<Extension> CreateExtension( | |
| 121 Extension::Location location, | |
| 122 base::DictionaryValue* test_extension_value) { | |
| 108 std::string error; | 123 std::string error; |
| 109 const FilePath test_extension_path; | 124 const FilePath test_extension_path; |
| 110 scoped_ptr<base::DictionaryValue> test_extension_value( | |
| 111 ParseDictionary("{\"name\": \"Test\", \"version\": \"1.0\"}")); | |
| 112 scoped_refptr<Extension> extension(Extension::Create( | 125 scoped_refptr<Extension> extension(Extension::Create( |
| 113 test_extension_path, | 126 test_extension_path, |
| 114 location, | 127 location, |
| 115 *test_extension_value.get(), | 128 *test_extension_value, |
| 116 Extension::NO_FLAGS, | 129 Extension::NO_FLAGS, |
| 117 &error)); | 130 &error)); |
| 118 EXPECT_TRUE(error.empty()) << "Could not parse test extension " << error; | 131 EXPECT_TRUE(error.empty()) << "Could not parse test extension " << error; |
| 119 return extension; | 132 return extension; |
| 120 } | 133 } |
| 121 | 134 |
| 135 bool HasPrivateInfo(base::DictionaryValue* val) { | |
|
Aaron Boodman
2012/08/07 01:03:25
HasPrivacySensitiveFields
SanjoyPal
2012/08/14 11:14:13
Done.
| |
| 136 std::string result; | |
| 137 if (val->GetString(keys::kUrlKey, &result) || | |
| 138 val->GetString(keys::kTitleKey, &result) || | |
| 139 val->GetString(keys::kFaviconUrlKey, &result)) | |
| 140 return true; | |
| 141 return false; | |
| 142 } | |
| 143 | |
| 122 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, | 144 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
| 123 const std::string& args, | 145 const std::string& args, |
| 124 Browser* browser) { | 146 Browser* browser) { |
| 125 return RunFunctionAndReturnError(function, args, browser, NONE); | 147 return RunFunctionAndReturnError(function, args, browser, NONE); |
| 126 } | 148 } |
| 127 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, | 149 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
| 128 const std::string& args, | 150 const std::string& args, |
| 129 Browser* browser, | 151 Browser* browser, |
| 130 RunFunctionFlags flags) { | 152 RunFunctionFlags flags) { |
| 131 scoped_refptr<ExtensionFunction> function_owner(function); | 153 scoped_refptr<ExtensionFunction> function_owner(function); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 if (!response_delegate.HasResponse()) { | 237 if (!response_delegate.HasResponse()) { |
| 216 response_delegate.set_should_post_quit(true); | 238 response_delegate.set_should_post_quit(true); |
| 217 ui_test_utils::RunMessageLoop(); | 239 ui_test_utils::RunMessageLoop(); |
| 218 } | 240 } |
| 219 | 241 |
| 220 EXPECT_TRUE(response_delegate.HasResponse()); | 242 EXPECT_TRUE(response_delegate.HasResponse()); |
| 221 return response_delegate.GetResponse(); | 243 return response_delegate.GetResponse(); |
| 222 } | 244 } |
| 223 | 245 |
| 224 } // namespace extension_function_test_utils | 246 } // namespace extension_function_test_utils |
| OLD | NEW |