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

Side by Side Diff: chrome/test/automation/extension_proxy_uitest.cc

Issue 10115018: Convert the infobars interactive_ui_test to a browser_test. Remove the ExtensionProxy class which… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/memory/ref_counted.h"
6 #include "base/path_service.h"
7 #include "chrome/common/chrome_paths.h"
8 #include "chrome/test/automation/automation_proxy.h"
9 #include "chrome/test/automation/browser_proxy.h"
10 #include "chrome/test/automation/extension_proxy.h"
11 #include "chrome/test/automation/tab_proxy.h"
12 #include "chrome/test/base/layout_test_http_server.h"
13 #include "chrome/test/ui/ui_test.h"
14
15 namespace {
16
17 // These tests are not meant to test the extension system itself, but to verify
18 // the correctness of ExtensionProxy and the AutomationProvider implementation
19 // behind it.
20 class ExtensionProxyUITest : public UITest {
21 public:
22 ExtensionProxyUITest() {}
23
24 virtual void SetUp() {
25 UITest::SetUp();
26 simple_extension_= InstallSimpleBrowserActionExtension();
27 ASSERT_TRUE(simple_extension_.get());
28 }
29
30 protected:
31 // Installs a simple browser action extension from the sample_extensions
32 // folder. Returns an ExtensionProxy, which could be NULL.
33 scoped_refptr<ExtensionProxy> InstallSimpleBrowserActionExtension() {
34 return automation()->InstallExtension(
35 test_data_directory_.AppendASCII("extensions").AppendASCII("uitest").
36 AppendASCII("simple_browser_action.crx"), false);
37 }
38
39 // Installs a extension which, when clicking the browser action, renames
40 // the current tab to the tab's index. Returns an ExtensionProxy,
41 // which could be NULL.
42 scoped_refptr<ExtensionProxy> InstallRenameTabExtension() {
43 return automation()->InstallExtension(
44 test_data_directory_.AppendASCII("extensions").AppendASCII("uitest").
45 AppendASCII("rename_tab.crx"), false);
46 }
47
48 // The google translate extension, which is installed on test setup.
49 scoped_refptr<ExtensionProxy> simple_extension_;
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(ExtensionProxyUITest);
53 };
54
55 TEST_F(ExtensionProxyUITest, NoSuchExtension) {
56 ASSERT_TRUE(simple_extension_->Uninstall());
57
58 // A proxy referring to an uninstalled extension should return false for all
59 // calls without actually invoking the extension system.
60 ASSERT_FALSE(simple_extension_->Uninstall());
61 ASSERT_FALSE(simple_extension_->Enable());
62 ASSERT_FALSE(simple_extension_->Disable());
63 scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0);
64 ASSERT_TRUE(browser.get());
65 ASSERT_FALSE(simple_extension_->
66 ExecuteActionInActiveTabAsync(browser.get()));
67 ASSERT_FALSE(simple_extension_->MoveBrowserAction(0));
68 std::string name, version;
69 int index;
70 ASSERT_FALSE(simple_extension_->GetName(&name));
71 ASSERT_FALSE(simple_extension_->GetVersion(&version));
72 ASSERT_FALSE(simple_extension_->GetBrowserActionIndex(&index));
73 }
74
75 TEST_F(ExtensionProxyUITest, EnableDisable) {
76 ASSERT_TRUE(simple_extension_->Disable());
77 ASSERT_TRUE(simple_extension_->Enable());
78 ASSERT_TRUE(simple_extension_->Disable());
79 }
80
81 TEST_F(ExtensionProxyUITest, Uninstall) {
82 ASSERT_TRUE(simple_extension_->Uninstall());
83
84 // Uninstall a disabled extension.
85 simple_extension_ = InstallSimpleBrowserActionExtension();
86 ASSERT_TRUE(simple_extension_.get());
87 ASSERT_TRUE(simple_extension_->Disable());
88 ASSERT_TRUE(simple_extension_->Uninstall());
89
90 // Uninstall a just enabled extension.
91 simple_extension_ = InstallSimpleBrowserActionExtension();
92 ASSERT_TRUE(simple_extension_.get());
93 ASSERT_TRUE(simple_extension_->Disable());
94 ASSERT_TRUE(simple_extension_->Enable());
95 ASSERT_TRUE(simple_extension_->Uninstall());
96 }
97
98 // http://crbug.com/44370
99 TEST_F(ExtensionProxyUITest, DISABLED_ExecuteBrowserActionInActiveTabAsync) {
100 scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0);
101 ASSERT_TRUE(browser.get());
102 scoped_refptr<ExtensionProxy> rename_tab_extension =
103 InstallRenameTabExtension();
104 ASSERT_TRUE(rename_tab_extension.get());
105
106 // Need to use http in order for the extension to be able to inject
107 // javascript into the page. Extensions do not have permissions for
108 // chrome://* urls.
109 FilePath path;
110 // The root directory for the http server does not matter in this case,
111 // but we have to pick something.
112 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
113 // TODO(phajdan.jr): Use net/test/test_server instead of layout test server.
114 LayoutTestHttpServer http_server(path, 1365);
115 ASSERT_TRUE(http_server.Start());
116 GURL localhost = GURL("http://localhost:1365");
117 NavigateToURL(localhost);
118
119 // Click the browser action, which should rename the tab title to
120 // the tab's index.
121 ASSERT_TRUE(rename_tab_extension->
122 ExecuteActionInActiveTabAsync(browser.get()));
123
124 bool result;
125 std::string message;
126
127 if (!automation()->GetExtensionTestResult(&result, &message))
128 FAIL() << "Could not send WaitForExtensionTestResult message";
129 ASSERT_TRUE(result) << "Extension test message: " << message;
130
131 scoped_refptr<TabProxy> display_tab = browser->GetTab(0);
132 ASSERT_TRUE(display_tab);
133 std::wstring title_wstring;
134 ASSERT_TRUE(display_tab->GetTabTitle(&title_wstring));
135 ASSERT_STREQ(L"0", title_wstring.c_str());
136
137 // Click the action again right after navigating to a new page.
138 ASSERT_TRUE(browser->AppendTab(localhost));
139 display_tab = browser->GetTab(1);
140 ASSERT_TRUE(display_tab);
141 ASSERT_TRUE(rename_tab_extension->
142 ExecuteActionInActiveTabAsync(browser.get()));
143 if (!automation()->GetExtensionTestResult(&result, &message))
144 FAIL() << "Could not send WaitForExtensionTestResult message";
145 ASSERT_TRUE(result) << "Extension test message: " << message;
146 ASSERT_TRUE(display_tab->GetTabTitle(&title_wstring));
147 ASSERT_STREQ(L"1", title_wstring.c_str());
148
149 // Do not forget to stop the server.
150 ASSERT_TRUE(http_server.Stop());
151 }
152
153 // Flaky, http://crbug.com/59441.
154 TEST_F(ExtensionProxyUITest, DISABLED_MoveBrowserAction) {
155 int action_index;
156
157 scoped_refptr<ExtensionProxy> rename_tab_extension =
158 InstallRenameTabExtension();
159 ASSERT_TRUE(rename_tab_extension.get());
160
161 ASSERT_TRUE(simple_extension_->GetBrowserActionIndex(&action_index));
162 ASSERT_EQ(0, action_index);
163 ASSERT_TRUE(rename_tab_extension->GetBrowserActionIndex(&action_index));
164 ASSERT_EQ(1, action_index);
165
166 // Move google translate to the end, then beginning, and verify.
167 ASSERT_TRUE(simple_extension_->MoveBrowserAction(1));
168 ASSERT_TRUE(simple_extension_->GetBrowserActionIndex(&action_index));
169 ASSERT_EQ(1, action_index);
170 ASSERT_TRUE(rename_tab_extension->GetBrowserActionIndex(&action_index));
171 ASSERT_EQ(0, action_index);
172
173 ASSERT_TRUE(simple_extension_->MoveBrowserAction(0));
174 ASSERT_TRUE(simple_extension_->GetBrowserActionIndex(&action_index));
175 ASSERT_EQ(0, action_index);
176 ASSERT_TRUE(rename_tab_extension->GetBrowserActionIndex(&action_index));
177 ASSERT_EQ(1, action_index);
178
179 // Try moving browser action to invalid index.
180 ASSERT_FALSE(simple_extension_->MoveBrowserAction(-1));
181 ASSERT_FALSE(simple_extension_->MoveBrowserAction(2));
182 }
183
184 // Flaky, http://crbug.com/59440.
185 TEST_F(ExtensionProxyUITest, DISABLED_GetProperty) {
186 std::string id;
187 ASSERT_TRUE(simple_extension_->GetId(&id));
188 ASSERT_EQ("aiglobglfckejlcpcbdokbkbjeemfhno", id);
189
190 std::string name;
191 ASSERT_TRUE(simple_extension_->GetName(&name));
192 ASSERT_EQ("Browser Action", name);
193
194 std::string version;
195 ASSERT_TRUE(simple_extension_->GetVersion(&version));
196 ASSERT_EQ("0.1.1", version);
197
198 int browser_action_index;
199 ASSERT_TRUE(simple_extension_->GetBrowserActionIndex(&browser_action_index));
200 ASSERT_EQ(0, browser_action_index);
201 }
202
203 } // namespace
OLDNEW
« no previous file with comments | « chrome/test/automation/extension_proxy.cc ('k') | chrome/test/data/extensions/uitest/rename_tab.crx » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698