| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_APITEST_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_APITEST_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_APITEST_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_APITEST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // (1) Setup initial browser state (e.g. create some bookmarks for the | 25 // (1) Setup initial browser state (e.g. create some bookmarks for the |
| 26 // bookmark test) | 26 // bookmark test) |
| 27 // (2) Call ASSERT_TRUE(RunExtensionTest(name)); | 27 // (2) Call ASSERT_TRUE(RunExtensionTest(name)); |
| 28 // (3) In your extension code, run your test and call chrome.test.pass or | 28 // (3) In your extension code, run your test and call chrome.test.pass or |
| 29 // chrome.test.fail | 29 // chrome.test.fail |
| 30 // (4) Verify expected browser state. | 30 // (4) Verify expected browser state. |
| 31 // TODO(erikkay): There should also be a way to drive events in these tests. | 31 // TODO(erikkay): There should also be a way to drive events in these tests. |
| 32 | 32 |
| 33 class ExtensionApiTest : public ExtensionBrowserTest { | 33 class ExtensionApiTest : public ExtensionBrowserTest { |
| 34 public: | 34 public: |
| 35 // Flags used to configure how the tests are run. |
| 36 enum Flags { |
| 37 kFlagNone = 0, |
| 38 |
| 39 // Allow the extension to run in incognito mode. |
| 40 kFlagEnableIncognito = 1 << 0, |
| 41 |
| 42 // Launch the test page in an incognito window. |
| 43 kFlagUseIncognito = 1 << 1, |
| 44 |
| 45 // Allow file access for the extension. |
| 46 kFlagEnableFileAccess = 1 << 2, |
| 47 |
| 48 // Loads the extension with location COMPONENT. |
| 49 kFlagLoadAsComponent = 1 << 3, |
| 50 |
| 51 // Launch the extension in a platform app shell. |
| 52 kFlagLaunchAppShell = 1 << 4 |
| 53 }; |
| 54 |
| 35 ExtensionApiTest(); | 55 ExtensionApiTest(); |
| 36 virtual ~ExtensionApiTest(); | 56 virtual ~ExtensionApiTest(); |
| 37 | 57 |
| 38 protected: | 58 protected: |
| 39 // Helper class that observes tests failing or passing. Observation starts | 59 // Helper class that observes tests failing or passing. Observation starts |
| 40 // when the class is constructed. Get the next result by calling | 60 // when the class is constructed. Get the next result by calling |
| 41 // GetNextResult() and message() if GetNextResult() return false. If there | 61 // GetNextResult() and message() if GetNextResult() return false. If there |
| 42 // are no results, this method will pump the UI message loop until one is | 62 // are no results, this method will pump the UI message loop until one is |
| 43 // received. | 63 // received. |
| 44 class ResultCatcher : public content::NotificationObserver { | 64 class ResultCatcher : public content::NotificationObserver { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 bool RunExtensionTestIncognitoNoFileAccess(const char* extension_name); | 116 bool RunExtensionTestIncognitoNoFileAccess(const char* extension_name); |
| 97 | 117 |
| 98 // If not empty, Load |extension_name|, load |page_url| and wait for pass / | 118 // If not empty, Load |extension_name|, load |page_url| and wait for pass / |
| 99 // fail notification from the extension API on the page. Note that if | 119 // fail notification from the extension API on the page. Note that if |
| 100 // |page_url| is not a valid url, it will be treated as a resource within | 120 // |page_url| is not a valid url, it will be treated as a resource within |
| 101 // the extension. |extension_name| is a directory in | 121 // the extension. |extension_name| is a directory in |
| 102 // "test/data/extensions/api_test". | 122 // "test/data/extensions/api_test". |
| 103 bool RunExtensionSubtest(const char* extension_name, | 123 bool RunExtensionSubtest(const char* extension_name, |
| 104 const std::string& page_url); | 124 const std::string& page_url); |
| 105 | 125 |
| 106 // Same as RunExtensionSubtest, but loads extension as component. | 126 // Same as RunExtensionSubtest, except run with the specific |flags|. |
| 107 bool RunComponentExtensionSubtest(const char* extension_name, | 127 bool RunExtensionSubtest(const char* extension_name, |
| 108 const std::string& page_url); | 128 const std::string& page_url, |
| 109 | 129 int flags); |
| 110 // Same as RunExtensionSubtest, but disables file access. | |
| 111 bool RunExtensionSubtestNoFileAccess(const char* extension_name, | |
| 112 const std::string& page_url); | |
| 113 | |
| 114 // Same as RunExtensionSubtest, but enables the extension for incognito mode. | |
| 115 bool RunExtensionSubtestIncognito(const char* extension_name, | |
| 116 const std::string& page_url); | |
| 117 | |
| 118 // Same as RunExtensionSubtestIncognito, but disables file access. | |
| 119 bool RunExtensionSubtestIncognitoNoFileAccess(const char* extension_name, | |
| 120 const std::string& page_url); | |
| 121 | 130 |
| 122 // Load |page_url| and wait for pass / fail notification from the extension | 131 // Load |page_url| and wait for pass / fail notification from the extension |
| 123 // API on the page. | 132 // API on the page. |
| 124 bool RunPageTest(const std::string& page_url); | 133 bool RunPageTest(const std::string& page_url); |
| 125 | 134 |
| 126 // Similar to RunExtensionTest, except used for running tests in platform app | 135 // Similar to RunExtensionTest, except used for running tests in platform app |
| 127 // shell windows. | 136 // shell windows. |
| 128 bool RunPlatformAppTest(const char* extension_name); | 137 bool RunPlatformAppTest(const char* extension_name); |
| 129 | 138 |
| 130 // Start the test server, and store details of its state. Those details | 139 // Start the test server, and store details of its state. Those details |
| 131 // will be available to javascript tests using chrome.test.getConfig(). | 140 // will be available to javascript tests using chrome.test.getConfig(). |
| 132 bool StartTestServer(); | 141 bool StartTestServer(); |
| 133 | 142 |
| 134 // Start the test WebSocket server, and store details of its state. Those | 143 // Start the test WebSocket server, and store details of its state. Those |
| 135 // details will be available to javascript tests using | 144 // details will be available to javascript tests using |
| 136 // chrome.test.getConfig(). | 145 // chrome.test.getConfig(). |
| 137 bool StartWebSocketServer(const FilePath& root_directory); | 146 bool StartWebSocketServer(const FilePath& root_directory); |
| 138 | 147 |
| 139 // Test that exactly one extension loaded. If so, return a pointer to | 148 // Test that exactly one extension loaded. If so, return a pointer to |
| 140 // the extension. If not, return NULL and set message_. | 149 // the extension. If not, return NULL and set message_. |
| 141 const Extension* GetSingleLoadedExtension(); | 150 const Extension* GetSingleLoadedExtension(); |
| 142 | 151 |
| 143 // All extensions tested by ExtensionApiTest are in the "api_test" dir. | 152 // All extensions tested by ExtensionApiTest are in the "api_test" dir. |
| 144 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; | 153 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; |
| 145 | 154 |
| 146 // If it failed, what was the error message? | 155 // If it failed, what was the error message? |
| 147 std::string message_; | 156 std::string message_; |
| 148 | 157 |
| 149 private: | 158 private: |
| 150 enum Flags { | |
| 151 kFlagNone = 0, | |
| 152 kFlagEnableIncognito = 1 << 0, | |
| 153 kFlagEnableFileAccess = 1 << 1, | |
| 154 kFlagLoadAsComponent = 1 << 2, | |
| 155 kFlagLaunchAppShell = 1 << 3 | |
| 156 }; | |
| 157 bool RunExtensionTestImpl(const char* extension_name, | 159 bool RunExtensionTestImpl(const char* extension_name, |
| 158 const std::string& test_page, | 160 const std::string& test_page, |
| 159 int flags); | 161 int flags); |
| 160 | 162 |
| 161 // Hold details of the test, set in C++, which can be accessed by | 163 // Hold details of the test, set in C++, which can be accessed by |
| 162 // javascript using chrome.test.getConfig(). | 164 // javascript using chrome.test.getConfig(). |
| 163 scoped_ptr<DictionaryValue> test_config_; | 165 scoped_ptr<DictionaryValue> test_config_; |
| 164 | 166 |
| 165 // Hold the test WebSocket server. | 167 // Hold the test WebSocket server. |
| 166 scoped_ptr<ui_test_utils::TestWebSocketServer> websocket_server_; | 168 scoped_ptr<ui_test_utils::TestWebSocketServer> websocket_server_; |
| 167 }; | 169 }; |
| 168 | 170 |
| 169 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_APITEST_H_ | 171 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_APITEST_H_ |
| OLD | NEW |