| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 testing::AssertionResult CanReadClipboard(const Extension* extension, | 122 testing::AssertionResult CanReadClipboard(const Extension* extension, |
| 123 const GURL& url) { | 123 const GURL& url) { |
| 124 return TestScriptResult(extension, url, "tests.canReadClipboard()"); | 124 return TestScriptResult(extension, url, "tests.canReadClipboard()"); |
| 125 } | 125 } |
| 126 | 126 |
| 127 testing::AssertionResult CanWriteClipboard(const Extension* extension, | 127 testing::AssertionResult CanWriteClipboard(const Extension* extension, |
| 128 const GURL& url) { | 128 const GURL& url) { |
| 129 return TestScriptResult(extension, url, "tests.canWriteClipboard()"); | 129 return TestScriptResult(extension, url, "tests.canWriteClipboard()"); |
| 130 } | 130 } |
| 131 | 131 |
| 132 testing::AssertionResult CanReadClipboardInAboutBlankFrame( |
| 133 const Extension* extension, |
| 134 const GURL& url) { |
| 135 return TestScriptResult(extension, url, |
| 136 "tests.canReadClipboardInAboutBlankFrame()"); |
| 137 } |
| 138 |
| 139 testing::AssertionResult CanWriteClipboardInAboutBlankFrame( |
| 140 const Extension* extension, |
| 141 const GURL& url) { |
| 142 return TestScriptResult(extension, url, |
| 143 "tests.canWriteClipboardInAboutBlankFrame()"); |
| 144 } |
| 145 |
| 132 testing::AssertionResult HasUnlimitedStorage(const Extension* extension, | 146 testing::AssertionResult HasUnlimitedStorage(const Extension* extension, |
| 133 const GURL& url) { | 147 const GURL& url) { |
| 134 if (profile()->GetSpecialStoragePolicy()->IsStorageUnlimited(url)) | 148 if (profile()->GetSpecialStoragePolicy()->IsStorageUnlimited(url)) |
| 135 return testing::AssertionSuccess(); | 149 return testing::AssertionSuccess(); |
| 136 return testing::AssertionFailure(); | 150 return testing::AssertionFailure(); |
| 137 } | 151 } |
| 138 | 152 |
| 139 private: | 153 private: |
| 140 extensions::TestExtensionDir test_extension_dir_; | 154 extensions::TestExtensionDir test_extension_dir_; |
| 141 }; | 155 }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 155 } | 169 } |
| 156 | 170 |
| 157 IN_PROC_BROWSER_TEST_F(ContentCapabilitiesTest, ClipboardRead) { | 171 IN_PROC_BROWSER_TEST_F(ContentCapabilitiesTest, ClipboardRead) { |
| 158 InitializeTestServer(); | 172 InitializeTestServer(); |
| 159 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( | 173 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( |
| 160 MakeJSONList("http://foo.example.com/*"), MakeJSONList("clipboardRead")); | 174 MakeJSONList("http://foo.example.com/*"), MakeJSONList("clipboardRead")); |
| 161 EXPECT_TRUE( | 175 EXPECT_TRUE( |
| 162 CanReadClipboard(extension.get(), GetTestURLFor("foo.example.com"))); | 176 CanReadClipboard(extension.get(), GetTestURLFor("foo.example.com"))); |
| 163 EXPECT_FALSE( | 177 EXPECT_FALSE( |
| 164 CanReadClipboard(extension.get(), GetTestURLFor("bar.example.com"))); | 178 CanReadClipboard(extension.get(), GetTestURLFor("bar.example.com"))); |
| 179 EXPECT_TRUE( |
| 180 CanReadClipboardInAboutBlankFrame(extension.get(), |
| 181 GetTestURLFor("foo.example.com"))); |
| 182 EXPECT_FALSE( |
| 183 CanReadClipboardInAboutBlankFrame(extension.get(), |
| 184 GetTestURLFor("bar.example.com"))); |
| 165 // TODO(dcheng): This should be false, but we cannot currently execute testing | 185 // TODO(dcheng): This should be false, but we cannot currently execute testing |
| 166 // script without a user gesture. | 186 // script without a user gesture. |
| 167 EXPECT_TRUE( | 187 EXPECT_TRUE( |
| 168 CanWriteClipboard(extension.get(), GetTestURLFor("foo.example.com"))); | 188 CanWriteClipboard(extension.get(), GetTestURLFor("foo.example.com"))); |
| 169 } | 189 } |
| 170 | 190 |
| 171 IN_PROC_BROWSER_TEST_F(ContentCapabilitiesTest, ClipboardWrite) { | 191 IN_PROC_BROWSER_TEST_F(ContentCapabilitiesTest, ClipboardWrite) { |
| 172 InitializeTestServer(); | 192 InitializeTestServer(); |
| 173 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( | 193 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( |
| 174 MakeJSONList("http://foo.example.com/*"), MakeJSONList("clipboardWrite")); | 194 MakeJSONList("http://foo.example.com/*"), MakeJSONList("clipboardWrite")); |
| 175 EXPECT_TRUE( | 195 EXPECT_TRUE( |
| 176 CanWriteClipboard(extension.get(), GetTestURLFor("foo.example.com"))); | 196 CanWriteClipboard(extension.get(), GetTestURLFor("foo.example.com"))); |
| 197 EXPECT_TRUE( |
| 198 CanWriteClipboardInAboutBlankFrame(extension.get(), |
| 199 GetTestURLFor("foo.example.com"))); |
| 177 // TODO(dcheng): This should be false, but we cannot currently execute testing | 200 // TODO(dcheng): This should be false, but we cannot currently execute testing |
| 178 // script without a user gesture. | 201 // script without a user gesture. |
| 179 EXPECT_TRUE( | 202 EXPECT_TRUE( |
| 180 CanWriteClipboard(extension.get(), GetTestURLFor("bar.example.com"))); | 203 CanWriteClipboard(extension.get(), GetTestURLFor("bar.example.com"))); |
| 204 EXPECT_TRUE( |
| 205 CanWriteClipboardInAboutBlankFrame(extension.get(), |
| 206 GetTestURLFor("bar.example.com"))); |
| 207 |
| 181 EXPECT_FALSE( | 208 EXPECT_FALSE( |
| 182 CanReadClipboard(extension.get(), GetTestURLFor("foo.example.com"))); | 209 CanReadClipboard(extension.get(), GetTestURLFor("foo.example.com"))); |
| 183 } | 210 } |
| 184 | 211 |
| 185 IN_PROC_BROWSER_TEST_F(ContentCapabilitiesTest, ClipboardReadWrite) { | 212 IN_PROC_BROWSER_TEST_F(ContentCapabilitiesTest, ClipboardReadWrite) { |
| 186 InitializeTestServer(); | 213 InitializeTestServer(); |
| 187 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( | 214 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( |
| 188 MakeJSONList("http://foo.example.com/*"), | 215 MakeJSONList("http://foo.example.com/*"), |
| 189 MakeJSONList("clipboardRead", "clipboardWrite")); | 216 MakeJSONList("clipboardRead", "clipboardWrite")); |
| 190 EXPECT_TRUE( | 217 EXPECT_TRUE( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // This extension has unlimitedStorage but doesn't grant it to foo.example.com | 256 // This extension has unlimitedStorage but doesn't grant it to foo.example.com |
| 230 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( | 257 scoped_refptr<const Extension> extension = LoadExtensionWithCapabilities( |
| 231 MakeJSONList("http://foo.example.com/*"), MakeJSONList("clipboardRead"), | 258 MakeJSONList("http://foo.example.com/*"), MakeJSONList("clipboardRead"), |
| 232 MakeJSONList("unlimitedStorage")); | 259 MakeJSONList("unlimitedStorage")); |
| 233 | 260 |
| 234 EXPECT_TRUE( | 261 EXPECT_TRUE( |
| 235 HasUnlimitedStorage(extension.get(), extension->GetResourceURL(""))); | 262 HasUnlimitedStorage(extension.get(), extension->GetResourceURL(""))); |
| 236 EXPECT_FALSE( | 263 EXPECT_FALSE( |
| 237 HasUnlimitedStorage(extension.get(), GetTestURLFor("foo.example.com"))); | 264 HasUnlimitedStorage(extension.get(), GetTestURLFor("foo.example.com"))); |
| 238 } | 265 } |
| OLD | NEW |