Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_private_apitest.cc

Issue 2058233002: Rewrite simple uses of base::ListValue::Append() taking a raw pointer var. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: less comments more ownership Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <memory>
8 #include <utility>
9
7 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
8 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
9 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr ivate_api.h" 14 #include "chrome/browser/extensions/api/webrtc_logging_private/webrtc_logging_pr ivate_api.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 15 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/extension_function_test_utils.h" 16 #include "chrome/browser/extensions/extension_function_test_utils.h"
14 #include "chrome/browser/extensions/extension_tab_util.h" 17 #include "chrome/browser/extensions/extension_tab_util.h"
15 #include "chrome/browser/media/webrtc_log_uploader.h" 18 #include "chrome/browser/media/webrtc_log_uploader.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 25 matching lines...) Expand all
42 static const char kTestLoggingSessionIdValue[] = "0123456789abcdef"; 45 static const char kTestLoggingSessionIdValue[] = "0123456789abcdef";
43 static const char kTestLoggingUrl[] = "dummy url string"; 46 static const char kTestLoggingUrl[] = "dummy url string";
44 47
45 std::string ParamsToString(const base::ListValue& parameters) { 48 std::string ParamsToString(const base::ListValue& parameters) {
46 std::string parameter_string; 49 std::string parameter_string;
47 EXPECT_TRUE(base::JSONWriter::Write(parameters, &parameter_string)); 50 EXPECT_TRUE(base::JSONWriter::Write(parameters, &parameter_string));
48 return parameter_string; 51 return parameter_string;
49 } 52 }
50 53
51 void InitializeTestMetaData(base::ListValue* parameters) { 54 void InitializeTestMetaData(base::ListValue* parameters) {
52 base::DictionaryValue* meta_data_entry = new base::DictionaryValue(); 55 std::unique_ptr<base::DictionaryValue> meta_data_entry(
56 new base::DictionaryValue());
53 meta_data_entry->SetString("key", kTestLoggingSessionIdKey); 57 meta_data_entry->SetString("key", kTestLoggingSessionIdKey);
54 meta_data_entry->SetString("value", kTestLoggingSessionIdValue); 58 meta_data_entry->SetString("value", kTestLoggingSessionIdValue);
55 base::ListValue* meta_data = new base::ListValue(); 59 std::unique_ptr<base::ListValue> meta_data(new base::ListValue());
56 meta_data->Append(meta_data_entry); 60 meta_data->Append(std::move(meta_data_entry));
57 meta_data_entry = new base::DictionaryValue(); 61 meta_data_entry.reset(new base::DictionaryValue());
58 meta_data_entry->SetString("key", "url"); 62 meta_data_entry->SetString("key", "url");
59 meta_data_entry->SetString("value", kTestLoggingUrl); 63 meta_data_entry->SetString("value", kTestLoggingUrl);
60 meta_data->Append(meta_data_entry); 64 meta_data->Append(std::move(meta_data_entry));
61 parameters->Append(meta_data); 65 parameters->Append(std::move(meta_data));
62 } 66 }
63 67
64 class WebrtcLoggingPrivateApiTest : public ExtensionApiTest { 68 class WebrtcLoggingPrivateApiTest : public ExtensionApiTest {
65 protected: 69 protected:
66 void SetUp() override { 70 void SetUp() override {
67 ExtensionApiTest::SetUp(); 71 ExtensionApiTest::SetUp();
68 extension_ = extensions::test_util::CreateEmptyExtension(); 72 extension_ = extensions::test_util::CreateEmptyExtension();
69 } 73 }
70 74
71 template<typename T> 75 template<typename T>
72 scoped_refptr<T> CreateFunction() { 76 scoped_refptr<T> CreateFunction() {
73 scoped_refptr<T> function(new T()); 77 scoped_refptr<T> function(new T());
74 function->set_extension(extension_.get()); 78 function->set_extension(extension_.get());
75 function->set_has_callback(true); 79 function->set_has_callback(true);
76 return function; 80 return function;
77 } 81 }
78 82
79 content::WebContents* web_contents() { 83 content::WebContents* web_contents() {
80 return browser()->tab_strip_model()->GetActiveWebContents(); 84 return browser()->tab_strip_model()->GetActiveWebContents();
81 } 85 }
82 86
83 void AppendTabIdAndUrl(base::ListValue* parameters) { 87 void AppendTabIdAndUrl(base::ListValue* parameters) {
84 base::DictionaryValue* request_info = new base::DictionaryValue(); 88 std::unique_ptr<base::DictionaryValue> request_info(
89 new base::DictionaryValue());
85 request_info->SetInteger( 90 request_info->SetInteger(
86 "tabId", extensions::ExtensionTabUtil::GetTabId(web_contents())); 91 "tabId", extensions::ExtensionTabUtil::GetTabId(web_contents()));
87 parameters->Append(request_info); 92 parameters->Append(std::move(request_info));
88 parameters->AppendString(web_contents()->GetURL().GetOrigin().spec()); 93 parameters->AppendString(web_contents()->GetURL().GetOrigin().spec());
89 } 94 }
90 95
91 bool RunFunction(UIThreadExtensionFunction* function, 96 bool RunFunction(UIThreadExtensionFunction* function,
92 const base::ListValue& parameters, 97 const base::ListValue& parameters,
93 bool expect_results) { 98 bool expect_results) {
94 std::unique_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 99 std::unique_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
95 function, ParamsToString(parameters), browser())); 100 function, ParamsToString(parameters), browser()));
96 if (expect_results) { 101 if (expect_results) {
97 EXPECT_TRUE(result.get()); 102 EXPECT_TRUE(result.get());
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 ASSERT_TRUE(StartAudioDebugRecordings(0)); 441 ASSERT_TRUE(StartAudioDebugRecordings(0));
437 ASSERT_TRUE(StopAudioDebugRecordings()); 442 ASSERT_TRUE(StopAudioDebugRecordings());
438 } 443 }
439 444
440 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest, 445 IN_PROC_BROWSER_TEST_F(WebrtcLoggingPrivateApiTest,
441 TestStartTimedAudioDebugRecordings) { 446 TestStartTimedAudioDebugRecordings) {
442 base::CommandLine::ForCurrentProcess()->AppendSwitch( 447 base::CommandLine::ForCurrentProcess()->AppendSwitch(
443 switches::kEnableAudioDebugRecordingsFromExtension); 448 switches::kEnableAudioDebugRecordingsFromExtension);
444 ASSERT_TRUE(StartAudioDebugRecordings(1)); 449 ASSERT_TRUE(StartAudioDebugRecordings(1));
445 } 450 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698