Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api_unittest.h" | 5 #include "extensions/browser/api_unittest.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "components/user_prefs/user_prefs.h" | 8 #include "components/user_prefs/user_prefs.h" |
| 9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 content::TestBrowserThreadBundle::DEFAULT)); | 46 content::TestBrowserThreadBundle::DEFAULT)); |
| 47 user_prefs::UserPrefs::Set(browser_context(), &testing_pref_service_); | 47 user_prefs::UserPrefs::Set(browser_context(), &testing_pref_service_); |
| 48 | 48 |
| 49 extension_ = ExtensionBuilder() | 49 extension_ = ExtensionBuilder() |
| 50 .SetManifest(DictionaryBuilder().Set("name", "Test").Set( | 50 .SetManifest(DictionaryBuilder().Set("name", "Test").Set( |
| 51 "version", "1.0")) | 51 "version", "1.0")) |
| 52 .SetLocation(Manifest::UNPACKED) | 52 .SetLocation(Manifest::UNPACKED) |
| 53 .Build(); | 53 .Build(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ApiUnitTest::CreateWebContents() { | |
| 57 if (!contents_) { | |
| 58 GURL url = BackgroundInfo::GetBackgroundURL(extension()); | |
| 59 if (url.is_empty()) | |
| 60 url = GURL(url::kAboutBlankURL); | |
| 61 content::SiteInstance* site_instance = | |
| 62 content::SiteInstance::CreateForURL(browser_context(), url); | |
| 63 contents_.reset(content::WebContents::Create( | |
| 64 content::WebContents::CreateParams(browser_context(), site_instance))); | |
| 65 } | |
| 66 } | |
| 67 | |
| 56 scoped_ptr<base::Value> ApiUnitTest::RunFunctionAndReturnValue( | 68 scoped_ptr<base::Value> ApiUnitTest::RunFunctionAndReturnValue( |
| 57 UIThreadExtensionFunction* function, | 69 UIThreadExtensionFunction* function, |
| 58 const std::string& args) { | 70 const std::string& args) { |
| 59 function->set_extension(extension()); | 71 function->set_extension(extension()); |
| 72 if (contents_) | |
| 73 function->SetRenderViewHost(contents_->GetRenderViewHost()); | |
| 60 return scoped_ptr<base::Value>(utils::RunFunctionAndReturnSingleResult( | 74 return scoped_ptr<base::Value>(utils::RunFunctionAndReturnSingleResult( |
| 61 function, args, browser_context())); | 75 function, args, browser_context())); |
| 62 } | 76 } |
| 63 | 77 |
| 64 scoped_ptr<base::DictionaryValue> ApiUnitTest::RunFunctionAndReturnDictionary( | 78 scoped_ptr<base::DictionaryValue> ApiUnitTest::RunFunctionAndReturnDictionary( |
| 65 UIThreadExtensionFunction* function, | 79 UIThreadExtensionFunction* function, |
| 66 const std::string& args) { | 80 const std::string& args) { |
| 67 base::Value* value = RunFunctionAndReturnValue(function, args).release(); | 81 base::Value* value = RunFunctionAndReturnValue(function, args).release(); |
| 68 base::DictionaryValue* dict = NULL; | 82 base::DictionaryValue* dict = NULL; |
| 69 | 83 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 87 | 101 |
| 88 // We expect to either have successfuly retrieved a list from the value, | 102 // We expect to either have successfuly retrieved a list from the value, |
| 89 // or the value to have been NULL. | 103 // or the value to have been NULL. |
| 90 EXPECT_TRUE(list || !value); | 104 EXPECT_TRUE(list || !value); |
| 91 return scoped_ptr<base::ListValue>(list); | 105 return scoped_ptr<base::ListValue>(list); |
| 92 } | 106 } |
| 93 | 107 |
| 94 std::string ApiUnitTest::RunFunctionAndReturnError( | 108 std::string ApiUnitTest::RunFunctionAndReturnError( |
| 95 UIThreadExtensionFunction* function, | 109 UIThreadExtensionFunction* function, |
| 96 const std::string& args) { | 110 const std::string& args) { |
| 97 function->set_extension(extension()); | 111 function->set_extension(extension()); |
|
James Cook
2015/01/17 00:51:29
Should this do the same if (content_) also? I thi
babu
2015/01/17 11:53:56
I missed this. It's fixed now.
| |
| 98 return utils::RunFunctionAndReturnError(function, args, browser_context()); | 112 return utils::RunFunctionAndReturnError(function, args, browser_context()); |
| 99 } | 113 } |
| 100 | 114 |
| 101 void ApiUnitTest::RunFunction(UIThreadExtensionFunction* function, | 115 void ApiUnitTest::RunFunction(UIThreadExtensionFunction* function, |
| 102 const std::string& args) { | 116 const std::string& args) { |
| 103 RunFunctionAndReturnValue(function, args); | 117 RunFunctionAndReturnValue(function, args); |
| 104 } | 118 } |
| 105 | 119 |
| 106 } // namespace extensions | 120 } // namespace extensions |
| OLD | NEW |