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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 GURL url = BackgroundInfo::GetBackgroundURL(extension()); | 64 GURL url = BackgroundInfo::GetBackgroundURL(extension()); |
65 if (url.is_empty()) | 65 if (url.is_empty()) |
66 url = GURL(url::kAboutBlankURL); | 66 url = GURL(url::kAboutBlankURL); |
67 contents_.reset( | 67 contents_.reset( |
68 content::WebContents::Create(content::WebContents::CreateParams( | 68 content::WebContents::Create(content::WebContents::CreateParams( |
69 browser_context(), | 69 browser_context(), |
70 content::SiteInstance::CreateForURL(browser_context(), url)))); | 70 content::SiteInstance::CreateForURL(browser_context(), url)))); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 scoped_ptr<base::Value> ApiUnitTest::RunFunctionAndReturnValue( | 74 std::unique_ptr<base::Value> ApiUnitTest::RunFunctionAndReturnValue( |
75 UIThreadExtensionFunction* function, | 75 UIThreadExtensionFunction* function, |
76 const std::string& args) { | 76 const std::string& args) { |
77 function->set_extension(extension()); | 77 function->set_extension(extension()); |
78 if (contents_) | 78 if (contents_) |
79 function->SetRenderFrameHost(contents_->GetMainFrame()); | 79 function->SetRenderFrameHost(contents_->GetMainFrame()); |
80 return scoped_ptr<base::Value>(utils::RunFunctionAndReturnSingleResult( | 80 return std::unique_ptr<base::Value>(utils::RunFunctionAndReturnSingleResult( |
81 function, args, browser_context())); | 81 function, args, browser_context())); |
82 } | 82 } |
83 | 83 |
84 scoped_ptr<base::DictionaryValue> ApiUnitTest::RunFunctionAndReturnDictionary( | 84 std::unique_ptr<base::DictionaryValue> |
85 UIThreadExtensionFunction* function, | 85 ApiUnitTest::RunFunctionAndReturnDictionary(UIThreadExtensionFunction* function, |
86 const std::string& args) { | 86 const std::string& args) { |
87 base::Value* value = RunFunctionAndReturnValue(function, args).release(); | 87 base::Value* value = RunFunctionAndReturnValue(function, args).release(); |
88 base::DictionaryValue* dict = NULL; | 88 base::DictionaryValue* dict = NULL; |
89 | 89 |
90 if (value && !value->GetAsDictionary(&dict)) | 90 if (value && !value->GetAsDictionary(&dict)) |
91 delete value; | 91 delete value; |
92 | 92 |
93 // We expect to either have successfuly retrieved a dictionary from the value, | 93 // We expect to either have successfuly retrieved a dictionary from the value, |
94 // or the value to have been NULL. | 94 // or the value to have been NULL. |
95 EXPECT_TRUE(dict || !value); | 95 EXPECT_TRUE(dict || !value); |
96 return scoped_ptr<base::DictionaryValue>(dict); | 96 return std::unique_ptr<base::DictionaryValue>(dict); |
97 } | 97 } |
98 | 98 |
99 scoped_ptr<base::ListValue> ApiUnitTest::RunFunctionAndReturnList( | 99 std::unique_ptr<base::ListValue> ApiUnitTest::RunFunctionAndReturnList( |
100 UIThreadExtensionFunction* function, | 100 UIThreadExtensionFunction* function, |
101 const std::string& args) { | 101 const std::string& args) { |
102 base::Value* value = RunFunctionAndReturnValue(function, args).release(); | 102 base::Value* value = RunFunctionAndReturnValue(function, args).release(); |
103 base::ListValue* list = NULL; | 103 base::ListValue* list = NULL; |
104 | 104 |
105 if (value && !value->GetAsList(&list)) | 105 if (value && !value->GetAsList(&list)) |
106 delete value; | 106 delete value; |
107 | 107 |
108 // We expect to either have successfuly retrieved a list from the value, | 108 // We expect to either have successfuly retrieved a list from the value, |
109 // or the value to have been NULL. | 109 // or the value to have been NULL. |
110 EXPECT_TRUE(list || !value); | 110 EXPECT_TRUE(list || !value); |
111 return scoped_ptr<base::ListValue>(list); | 111 return std::unique_ptr<base::ListValue>(list); |
112 } | 112 } |
113 | 113 |
114 std::string ApiUnitTest::RunFunctionAndReturnError( | 114 std::string ApiUnitTest::RunFunctionAndReturnError( |
115 UIThreadExtensionFunction* function, | 115 UIThreadExtensionFunction* function, |
116 const std::string& args) { | 116 const std::string& args) { |
117 function->set_extension(extension()); | 117 function->set_extension(extension()); |
118 if (contents_) | 118 if (contents_) |
119 function->SetRenderFrameHost(contents_->GetMainFrame()); | 119 function->SetRenderFrameHost(contents_->GetMainFrame()); |
120 return utils::RunFunctionAndReturnError(function, args, browser_context()); | 120 return utils::RunFunctionAndReturnError(function, args, browser_context()); |
121 } | 121 } |
122 | 122 |
123 void ApiUnitTest::RunFunction(UIThreadExtensionFunction* function, | 123 void ApiUnitTest::RunFunction(UIThreadExtensionFunction* function, |
124 const std::string& args) { | 124 const std::string& args) { |
125 RunFunctionAndReturnValue(function, args); | 125 RunFunctionAndReturnValue(function, args); |
126 } | 126 } |
127 | 127 |
128 } // namespace extensions | 128 } // namespace extensions |
OLD | NEW |