Chromium Code Reviews| 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 #include "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/extensions/extension_browsertest.h" | |
| 8 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/public/browser/navigation_entry.h" | 14 #include "content/public/browser/navigation_entry.h" |
| 15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 21 #include "extensions/common/constants.h" | 21 #include "extensions/common/constants.h" |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" | 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 const char kTestHtml[] = "/viewsource/test.html"; | 26 const char kTestHtml[] = "/viewsource/test.html"; |
| 27 const char kTestMedia[] = "/media/pink_noise_140ms.wav"; | 27 const char kTestMedia[] = "/media/pink_noise_140ms.wav"; |
| 28 } | 28 } |
| 29 | 29 |
| 30 typedef InProcessBrowserTest ViewSourceTest; | 30 typedef ExtensionBrowserTest ViewSourceTest; |
| 31 | 31 |
| 32 // This test renders a page in view-source and then checks to see if the title | 32 // This test renders a page in view-source and then checks to see if the title |
| 33 // set in the html was set successfully (it shouldn't because we rendered the | 33 // set in the html was set successfully (it shouldn't because we rendered the |
| 34 // page in view source). | 34 // page in view source). |
| 35 // Flaky; see http://crbug.com/72201. | 35 // Flaky; see http://crbug.com/72201. |
| 36 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { | 36 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { |
| 37 ASSERT_TRUE(embedded_test_server()->Start()); | 37 ASSERT_TRUE(embedded_test_server()->Start()); |
| 38 | 38 |
| 39 // First we navigate to our view-source test page. | 39 // First we navigate to our view-source test page. |
| 40 GURL url(content::kViewSourceScheme + std::string(":") + | 40 GURL url(content::kViewSourceScheme + std::string(":") + |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 182 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 183 browser()->tab_strip_model()->GetActiveWebContents(), | 183 browser()->tab_strip_model()->GetActiveWebContents(), |
| 184 "domAutomationController.send(document.getElementById('bar') === null);", | 184 "domAutomationController.send(document.getElementById('bar') === null);", |
| 185 &result)); | 185 &result)); |
| 186 EXPECT_TRUE(result); | 186 EXPECT_TRUE(result); |
| 187 EXPECT_FALSE(chrome::CanViewSource(browser())); | 187 EXPECT_FALSE(chrome::CanViewSource(browser())); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Verify that restoring a view-source tab for a Chrome extension works | 190 // Verify that restoring a view-source tab for a Chrome extension works |
| 191 // properly. See https://crbug.com/699428. | 191 // properly. See https://crbug.com/699428. |
| 192 IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceTabRestore) { | 192 IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceTabRestore) { |
|
Avi (use Gerrit)
2017/06/20 02:20:38
Can we move this test to chrome/browser/extensions
calamity
2017/06/21 08:37:49
Done.
| |
| 193 ASSERT_TRUE(embedded_test_server()->Start()); | 193 ASSERT_TRUE(embedded_test_server()->Start()); |
| 194 | 194 |
| 195 LoadExtension( | |
| 196 test_data_dir_.AppendASCII("browsertest/url_rewrite/bookmarks")); | |
| 197 | |
| 195 // Go to the Chrome bookmarks URL. It should redirect to the bookmark | 198 // Go to the Chrome bookmarks URL. It should redirect to the bookmark |
| 196 // manager Chrome extension. | 199 // manager Chrome extension. |
| 197 GURL bookmarks_url(chrome::kChromeUIBookmarksURL); | 200 GURL bookmarks_url(chrome::kChromeUIBookmarksURL); |
| 198 ui_test_utils::NavigateToURL(browser(), bookmarks_url); | 201 ui_test_utils::NavigateToURL(browser(), bookmarks_url); |
| 199 EXPECT_TRUE(chrome::CanViewSource(browser())); | 202 EXPECT_TRUE(chrome::CanViewSource(browser())); |
| 200 content::WebContents* bookmarks_tab = | 203 content::WebContents* bookmarks_tab = |
| 201 browser()->tab_strip_model()->GetActiveWebContents(); | 204 browser()->tab_strip_model()->GetActiveWebContents(); |
| 202 GURL bookmarks_extension_url = | 205 GURL bookmarks_extension_url = |
| 203 bookmarks_tab->GetMainFrame()->GetLastCommittedURL(); | 206 bookmarks_tab->GetMainFrame()->GetLastCommittedURL(); |
| 204 EXPECT_TRUE(bookmarks_extension_url.SchemeIs(extensions::kExtensionScheme)); | 207 EXPECT_TRUE(bookmarks_extension_url.SchemeIs(extensions::kExtensionScheme)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 "domAutomationController.send(document.body.innerText.length)", | 252 "domAutomationController.send(document.body.innerText.length)", |
| 250 &view_source_length)); | 253 &view_source_length)); |
| 251 EXPECT_GT(view_source_length, 0); | 254 EXPECT_GT(view_source_length, 0); |
| 252 | 255 |
| 253 std::string location; | 256 std::string location; |
| 254 EXPECT_TRUE(ExecuteScriptAndExtractString( | 257 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 255 view_source_tab, "domAutomationController.send(location.href)", | 258 view_source_tab, "domAutomationController.send(location.href)", |
| 256 &location)); | 259 &location)); |
| 257 EXPECT_EQ(bookmarks_extension_url, location); | 260 EXPECT_EQ(bookmarks_extension_url, location); |
| 258 } | 261 } |
| OLD | NEW |