| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/test_extension_dir.h" | 8 #include "chrome/browser/extensions/test_extension_dir.h" |
| 9 #include "chrome/browser/ui/browser_navigator_params.h" | 9 #include "chrome/browser/ui/browser_navigator_params.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 "});\n"; | 32 "});\n"; |
| 33 | 33 |
| 34 class ExtensionFetchTest : public ExtensionApiTest { | 34 class ExtensionFetchTest : public ExtensionApiTest { |
| 35 protected: | 35 protected: |
| 36 // Writes an empty background page and a text file called "text" with content | 36 // Writes an empty background page and a text file called "text" with content |
| 37 // "text content", then loads and returns the extension. |dir| must already | 37 // "text content", then loads and returns the extension. |dir| must already |
| 38 // have a manifest. | 38 // have a manifest. |
| 39 const Extension* WriteFilesAndLoadTestExtension(TestExtensionDir* dir) { | 39 const Extension* WriteFilesAndLoadTestExtension(TestExtensionDir* dir) { |
| 40 dir->WriteFile(FILE_PATH_LITERAL("text"), "text content"); | 40 dir->WriteFile(FILE_PATH_LITERAL("text"), "text content"); |
| 41 dir->WriteFile(FILE_PATH_LITERAL("bg.js"), ""); | 41 dir->WriteFile(FILE_PATH_LITERAL("bg.js"), ""); |
| 42 return LoadExtension(dir->unpacked_path()); | 42 return LoadExtension(dir->UnpackedPath()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Returns |kFetchScript| with |url_expression| substituted as its test URL. | 45 // Returns |kFetchScript| with |url_expression| substituted as its test URL. |
| 46 std::string GetFetchScript(const std::string& url_expression) { | 46 std::string GetFetchScript(const std::string& url_expression) { |
| 47 return base::StringPrintf(kFetchScript, url_expression.c_str()); | 47 return base::StringPrintf(kFetchScript, url_expression.c_str()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Returns |url| as a string surrounded by single quotes, for passing to | 50 // Returns |url| as a string surrounded by single quotes, for passing to |
| 51 // JavaScript as a string literal. | 51 // JavaScript as a string literal. |
| 52 std::string GetQuotedURL(const GURL& url) { | 52 std::string GetQuotedURL(const GURL& url) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 185 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 186 empty_tab, | 186 empty_tab, |
| 187 GetFetchScript(GetQuotedURL(extension->GetResourceURL("text"))), | 187 GetFetchScript(GetQuotedURL(extension->GetResourceURL("text"))), |
| 188 &fetch_result)); | 188 &fetch_result)); |
| 189 EXPECT_EQ("TypeError: Failed to fetch", fetch_result); | 189 EXPECT_EQ("TypeError: Failed to fetch", fetch_result); |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace | 192 } // namespace |
| 193 | 193 |
| 194 } // namespace extensions | 194 } // namespace extensions |
| OLD | NEW |