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

Side by Side Diff: chrome/browser/extensions/page_action_browsertest.cc

Issue 1378123003: Adding SSL ETS Tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ets
Patch Set: Rebase. Created 5 years, 1 month 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 (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 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/extensions/extension_action.h" 6 #include "chrome/browser/extensions/extension_action.h"
7 #include "chrome/browser/extensions/extension_action_manager.h" 7 #include "chrome/browser/extensions/extension_action_manager.h"
8 #include "chrome/browser/extensions/extension_action_test_util.h" 8 #include "chrome/browser/extensions/extension_action_test_util.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_tab_util.h" 10 #include "chrome/browser/extensions/extension_tab_util.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "extensions/browser/extension_registry.h" 15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/common/extension.h" 16 #include "extensions/common/extension.h"
17 #include "extensions/common/switches.h" 17 #include "extensions/common/switches.h"
18 18
19 namespace extensions { 19 namespace extensions {
20 namespace { 20 namespace {
21 21
22 const std::string kFeedPage = "files/feeds/feed.html"; 22 const std::string kFeedPage = "/feeds/feed.html";
23 const std::string kNoFeedPage = "files/feeds/no_feed.html"; 23 const std::string kNoFeedPage = "/feeds/no_feed.html";
24 const std::string kLocalization = 24 const std::string kLocalization =
25 "files/extensions/browsertest/title_localized_pa/simple.html"; 25 "/extensions/browsertest/title_localized_pa/simple.html";
26 26
27 const std::string kHashPageA = 27 const std::string kHashPageA =
28 "files/extensions/api_test/page_action/hash_change/test_page_A.html"; 28 "/extensions/api_test/page_action/hash_change/test_page_A.html";
29 const std::string kHashPageAHash = kHashPageA + "#asdf"; 29 const std::string kHashPageAHash = kHashPageA + "#asdf";
30 const std::string kHashPageB = 30 const std::string kHashPageB =
31 "files/extensions/api_test/page_action/hash_change/test_page_B.html"; 31 "/extensions/api_test/page_action/hash_change/test_page_B.html";
32 32
33 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionCrash25562) { 33 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionCrash25562) {
34 ASSERT_TRUE(test_server()->Start()); 34 ASSERT_TRUE(embedded_test_server()->Start());
35 35
36 base::CommandLine::ForCurrentProcess()->AppendSwitch( 36 base::CommandLine::ForCurrentProcess()->AppendSwitch(
37 switches::kAllowLegacyExtensionManifests); 37 switches::kAllowLegacyExtensionManifests);
38 38
39 // This page action will not show an icon, since it doesn't specify one but 39 // This page action will not show an icon, since it doesn't specify one but
40 // is included here to test for a crash (http://crbug.com/25562). 40 // is included here to test for a crash (http://crbug.com/25562).
41 ASSERT_TRUE(LoadExtension( 41 ASSERT_TRUE(LoadExtension(
42 test_data_dir_.AppendASCII("browsertest") 42 test_data_dir_.AppendASCII("browsertest")
43 .AppendASCII("crash_25562"))); 43 .AppendASCII("crash_25562")));
44 44
45 // Navigate to the feed page. 45 // Navigate to the feed page.
46 GURL feed_url = test_server()->GetURL(kFeedPage); 46 GURL feed_url = embedded_test_server()->GetURL(kFeedPage);
47 ui_test_utils::NavigateToURL(browser(), feed_url); 47 ui_test_utils::NavigateToURL(browser(), feed_url);
48 // We should now have one page action ready to go in the LocationBar. 48 // We should now have one page action ready to go in the LocationBar.
49 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); 49 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
50 } 50 }
51 51
52 // Tests that we can load page actions in the Omnibox. 52 // Tests that we can load page actions in the Omnibox.
53 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { 53 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) {
54 ASSERT_TRUE(test_server()->Start()); 54 ASSERT_TRUE(embedded_test_server()->Start());
55 55
56 ASSERT_TRUE(LoadExtension( 56 ASSERT_TRUE(LoadExtension(
57 test_data_dir_.AppendASCII("subscribe_page_action"))); 57 test_data_dir_.AppendASCII("subscribe_page_action")));
58 58
59 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); 59 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0));
60 60
61 // Navigate to the feed page. 61 // Navigate to the feed page.
62 GURL feed_url = test_server()->GetURL(kFeedPage); 62 GURL feed_url = embedded_test_server()->GetURL(kFeedPage);
63 ui_test_utils::NavigateToURL(browser(), feed_url); 63 ui_test_utils::NavigateToURL(browser(), feed_url);
64 // We should now have one page action ready to go in the LocationBar. 64 // We should now have one page action ready to go in the LocationBar.
65 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); 65 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
66 66
67 // Navigate to a page with no feed. 67 // Navigate to a page with no feed.
68 GURL no_feed = test_server()->GetURL(kNoFeedPage); 68 GURL no_feed = embedded_test_server()->GetURL(kNoFeedPage);
69 ui_test_utils::NavigateToURL(browser(), no_feed); 69 ui_test_utils::NavigateToURL(browser(), no_feed);
70 // Make sure the page action goes away. 70 // Make sure the page action goes away.
71 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); 71 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0));
72 } 72 }
73 73
74 // Tests that we don't lose the page action icon on in-page navigations. 74 // Tests that we don't lose the page action icon on in-page navigations.
75 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) { 75 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageActionInPageNavigation) {
76 ASSERT_TRUE(test_server()->Start()); 76 ASSERT_TRUE(embedded_test_server()->Start());
77 77
78 base::FilePath extension_path(test_data_dir_.AppendASCII("api_test") 78 base::FilePath extension_path(test_data_dir_.AppendASCII("api_test")
79 .AppendASCII("page_action") 79 .AppendASCII("page_action")
80 .AppendASCII("hash_change")); 80 .AppendASCII("hash_change"));
81 ASSERT_TRUE(LoadExtension(extension_path)); 81 ASSERT_TRUE(LoadExtension(extension_path));
82 82
83 // Page action should become visible when we navigate here. 83 // Page action should become visible when we navigate here.
84 GURL feed_url = test_server()->GetURL(kHashPageA); 84 GURL feed_url = embedded_test_server()->GetURL(kHashPageA);
85 ui_test_utils::NavigateToURL(browser(), feed_url); 85 ui_test_utils::NavigateToURL(browser(), feed_url);
86 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); 86 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
87 87
88 // In-page navigation, page action should remain. 88 // In-page navigation, page action should remain.
89 feed_url = test_server()->GetURL(kHashPageAHash); 89 feed_url = embedded_test_server()->GetURL(kHashPageAHash);
90 ui_test_utils::NavigateToURL(browser(), feed_url); 90 ui_test_utils::NavigateToURL(browser(), feed_url);
91 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); 91 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
92 92
93 // Not an in-page navigation, page action should go away. 93 // Not an in-page navigation, page action should go away.
94 feed_url = test_server()->GetURL(kHashPageB); 94 feed_url = embedded_test_server()->GetURL(kHashPageB);
95 ui_test_utils::NavigateToURL(browser(), feed_url); 95 ui_test_utils::NavigateToURL(browser(), feed_url);
96 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); 96 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0));
97 } 97 }
98 98
99 // Tests that the location bar forgets about unloaded page actions. 99 // Tests that the location bar forgets about unloaded page actions.
100 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { 100 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) {
101 ASSERT_TRUE(test_server()->Start()); 101 ASSERT_TRUE(embedded_test_server()->Start());
102 102
103 base::FilePath extension_path( 103 base::FilePath extension_path(
104 test_data_dir_.AppendASCII("subscribe_page_action")); 104 test_data_dir_.AppendASCII("subscribe_page_action"));
105 ASSERT_TRUE(LoadExtension(extension_path)); 105 ASSERT_TRUE(LoadExtension(extension_path));
106 106
107 // Navigation prompts the location bar to load page actions. 107 // Navigation prompts the location bar to load page actions.
108 GURL feed_url = test_server()->GetURL(kFeedPage); 108 GURL feed_url = embedded_test_server()->GetURL(kFeedPage);
109 ui_test_utils::NavigateToURL(browser(), feed_url); 109 ui_test_utils::NavigateToURL(browser(), feed_url);
110 content::WebContents* tab = 110 content::WebContents* tab =
111 browser()->tab_strip_model()->GetActiveWebContents(); 111 browser()->tab_strip_model()->GetActiveWebContents();
112 EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab)); 112 EXPECT_EQ(1u, extension_action_test_util::GetTotalPageActionCount(tab));
113 113
114 UnloadExtension(last_loaded_extension_id()); 114 UnloadExtension(last_loaded_extension_id());
115 115
116 // Make sure the page action goes away when it's unloaded. 116 // Make sure the page action goes away when it's unloaded.
117 EXPECT_EQ(0u, extension_action_test_util::GetTotalPageActionCount(tab)); 117 EXPECT_EQ(0u, extension_action_test_util::GetTotalPageActionCount(tab));
118 } 118 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 ReloadExtension(extensionA->id()); 168 ReloadExtension(extensionA->id());
169 169
170 LOG(INFO) << "Test completed : " 170 LOG(INFO) << "Test completed : "
171 << (base::TimeTicks::Now() - start_time).InMilliseconds() 171 << (base::TimeTicks::Now() - start_time).InMilliseconds()
172 << " ms" << std::flush; 172 << " ms" << std::flush;
173 } 173 }
174 174
175 // Tests that tooltips of a page action icon can be specified using UTF8. 175 // Tests that tooltips of a page action icon can be specified using UTF8.
176 // See http://crbug.com/25349. 176 // See http://crbug.com/25349.
177 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) { 177 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TitleLocalizationPageAction) {
178 ASSERT_TRUE(test_server()->Start()); 178 ASSERT_TRUE(embedded_test_server()->Start());
179 179
180 ExtensionRegistry* registry = 180 ExtensionRegistry* registry =
181 extensions::ExtensionRegistry::Get(browser()->profile()); 181 extensions::ExtensionRegistry::Get(browser()->profile());
182 const size_t size_before = registry->enabled_extensions().size(); 182 const size_t size_before = registry->enabled_extensions().size();
183 183
184 base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest") 184 base::FilePath extension_path(test_data_dir_.AppendASCII("browsertest")
185 .AppendASCII("title_localized_pa")); 185 .AppendASCII("title_localized_pa"));
186 const Extension* extension = LoadExtension(extension_path); 186 const Extension* extension = LoadExtension(extension_path);
187 ASSERT_TRUE(extension); 187 ASSERT_TRUE(extension);
188 188
189 // Any navigation prompts the location bar to load the page action. 189 // Any navigation prompts the location bar to load the page action.
190 GURL url = test_server()->GetURL(kLocalization); 190 GURL url = embedded_test_server()->GetURL(kLocalization);
191 ui_test_utils::NavigateToURL(browser(), url); 191 ui_test_utils::NavigateToURL(browser(), url);
192 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); 192 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
193 193
194 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); 194 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size());
195 195
196 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(), 196 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur: l10n page action").c_str(),
197 extension->description().c_str()); 197 extension->description().c_str());
198 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(), 198 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur is my name").c_str(),
199 extension->name().c_str()); 199 extension->name().c_str());
200 int tab_id = ExtensionTabUtil::GetTabId( 200 int tab_id = ExtensionTabUtil::GetTabId(
201 browser()->tab_strip_model()->GetActiveWebContents()); 201 browser()->tab_strip_model()->GetActiveWebContents());
202 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur").c_str(), 202 EXPECT_STREQ(base::WideToUTF8(L"Hreggvi\u00F0ur").c_str(),
203 ExtensionActionManager::Get(browser()->profile())-> 203 ExtensionActionManager::Get(browser()->profile())->
204 GetPageAction(*extension)-> 204 GetPageAction(*extension)->
205 GetTitle(tab_id).c_str()); 205 GetTitle(tab_id).c_str());
206 } 206 }
207 207
208 } // namespace 208 } // namespace
209 } // namespace extensions 209 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/isolated_app_browsertest.cc ('k') | chrome/browser/extensions/process_management_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698