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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api_unittest.cc

Issue 1739183003: Make extensions::DictionaryBuilder and extensions::ListValue unmovable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 6 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
7 #include "chrome/browser/extensions/extension_function_test_utils.h" 7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "chrome/browser/extensions/extension_service_test_base.h" 8 #include "chrome/browser/extensions/extension_service_test_base.h"
9 #include "chrome/browser/extensions/extension_tab_util.h" 9 #include "chrome/browser/extensions/extension_tab_util.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // An extension without "tabs" permission will see none of the 3 tabs. 100 // An extension without "tabs" permission will see none of the 3 tabs.
101 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension(); 101 scoped_refptr<const Extension> extension = test_util::CreateEmptyExtension();
102 scoped_ptr<base::ListValue> tabs_list_without_permission( 102 scoped_ptr<base::ListValue> tabs_list_without_permission(
103 RunTabsQueryFunction(browser(), extension.get(), kTitleAndURLQueryInfo)); 103 RunTabsQueryFunction(browser(), extension.get(), kTitleAndURLQueryInfo));
104 ASSERT_TRUE(tabs_list_without_permission); 104 ASSERT_TRUE(tabs_list_without_permission);
105 EXPECT_EQ(0u, tabs_list_without_permission->GetSize()); 105 EXPECT_EQ(0u, tabs_list_without_permission->GetSize());
106 106
107 // An extension with "tabs" permission however will see the third tab. 107 // An extension with "tabs" permission however will see the third tab.
108 scoped_refptr<const Extension> extension_with_permission = 108 scoped_refptr<const Extension> extension_with_permission =
109 ExtensionBuilder() 109 ExtensionBuilder()
110 .SetManifest(std::move( 110 .SetManifest(
111 DictionaryBuilder() 111 DictionaryBuilder()
112 .Set("name", "Extension with tabs permission") 112 .Set("name", "Extension with tabs permission")
113 .Set("version", "1.0") 113 .Set("version", "1.0")
114 .Set("manifest_version", 2) 114 .Set("manifest_version", 2)
115 .Set("permissions", std::move(ListBuilder().Append("tabs"))))) 115 .Set("permissions", ListBuilder().Append("tabs").Build())
116 .Build())
116 .Build(); 117 .Build();
117 scoped_ptr<base::ListValue> tabs_list_with_permission(RunTabsQueryFunction( 118 scoped_ptr<base::ListValue> tabs_list_with_permission(RunTabsQueryFunction(
118 browser(), extension_with_permission.get(), kTitleAndURLQueryInfo)); 119 browser(), extension_with_permission.get(), kTitleAndURLQueryInfo));
119 ASSERT_TRUE(tabs_list_with_permission); 120 ASSERT_TRUE(tabs_list_with_permission);
120 ASSERT_EQ(1u, tabs_list_with_permission->GetSize()); 121 ASSERT_EQ(1u, tabs_list_with_permission->GetSize());
121 122
122 const base::DictionaryValue* third_tab_info; 123 const base::DictionaryValue* third_tab_info;
123 ASSERT_TRUE(tabs_list_with_permission->GetDictionary(0, &third_tab_info)); 124 ASSERT_TRUE(tabs_list_with_permission->GetDictionary(0, &third_tab_info));
124 int third_tab_id = -1; 125 int third_tab_id = -1;
125 ASSERT_TRUE(third_tab_info->GetInteger("id", &third_tab_id)); 126 ASSERT_TRUE(third_tab_info->GetInteger("id", &third_tab_id));
(...skipping 22 matching lines...) Expand all
148 base::ASCIIToUTF16(tab_titles[i])); 149 base::ASCIIToUTF16(tab_titles[i]));
149 } 150 }
150 151
151 const char* kTitleAndURLQueryInfo = 152 const char* kTitleAndURLQueryInfo =
152 "[{\"title\": \"Sample title\", \"url\": \"*://www.google.com/*\"}]"; 153 "[{\"title\": \"Sample title\", \"url\": \"*://www.google.com/*\"}]";
153 154
154 // An extension with "host" permission will only see the third tab. 155 // An extension with "host" permission will only see the third tab.
155 scoped_refptr<const Extension> extension_with_permission = 156 scoped_refptr<const Extension> extension_with_permission =
156 ExtensionBuilder() 157 ExtensionBuilder()
157 .SetManifest( 158 .SetManifest(
158 std::move(DictionaryBuilder() 159 DictionaryBuilder()
159 .Set("name", "Extension with tabs permission") 160 .Set("name", "Extension with tabs permission")
160 .Set("version", "1.0") 161 .Set("version", "1.0")
161 .Set("manifest_version", 2) 162 .Set("manifest_version", 2)
162 .Set("permissions", std::move(ListBuilder().Append( 163 .Set("permissions",
163 "*://www.google.com/*"))))) 164 ListBuilder().Append("*://www.google.com/*").Build())
165 .Build())
164 .Build(); 166 .Build();
165 167
166 { 168 {
167 scoped_ptr<base::ListValue> tabs_list_with_permission(RunTabsQueryFunction( 169 scoped_ptr<base::ListValue> tabs_list_with_permission(RunTabsQueryFunction(
168 browser(), extension_with_permission.get(), kTitleAndURLQueryInfo)); 170 browser(), extension_with_permission.get(), kTitleAndURLQueryInfo));
169 ASSERT_TRUE(tabs_list_with_permission); 171 ASSERT_TRUE(tabs_list_with_permission);
170 ASSERT_EQ(1u, tabs_list_with_permission->GetSize()); 172 ASSERT_EQ(1u, tabs_list_with_permission->GetSize());
171 173
172 const base::DictionaryValue* third_tab_info; 174 const base::DictionaryValue* third_tab_info;
173 ASSERT_TRUE(tabs_list_with_permission->GetDictionary(0, &third_tab_info)); 175 ASSERT_TRUE(tabs_list_with_permission->GetDictionary(0, &third_tab_info));
(...skipping 23 matching lines...) Expand all
197 ASSERT_TRUE(first_tab_info->GetInteger("id", &first_tab_id)); 199 ASSERT_TRUE(first_tab_info->GetInteger("id", &first_tab_id));
198 EXPECT_TRUE(ContainsValue(expected_tabs_ids, first_tab_id)); 200 EXPECT_TRUE(ContainsValue(expected_tabs_ids, first_tab_id));
199 201
200 int third_tab_id = -1; 202 int third_tab_id = -1;
201 ASSERT_TRUE(third_tab_info->GetInteger("id", &third_tab_id)); 203 ASSERT_TRUE(third_tab_info->GetInteger("id", &third_tab_id));
202 EXPECT_TRUE(ContainsValue(expected_tabs_ids, third_tab_id)); 204 EXPECT_TRUE(ContainsValue(expected_tabs_ids, third_tab_id));
203 } 205 }
204 } 206 }
205 207
206 } // namespace extensions 208 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698