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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/browser_tabstrip.h" |
9 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
11 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
14 #include "net/test/test_server.h" | 15 #include "net/test/test_server.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 const char kTestHtml[] = "files/viewsource/test.html"; | 18 const char kTestHtml[] = "files/viewsource/test.html"; |
18 } | 19 } |
19 | 20 |
20 typedef InProcessBrowserTest ViewSourceTest; | 21 typedef InProcessBrowserTest ViewSourceTest; |
21 | 22 |
22 // This test renders a page in view-source and then checks to see if the title | 23 // This test renders a page in view-source and then checks to see if the title |
23 // set in the html was set successfully (it shouldn't because we rendered the | 24 // set in the html was set successfully (it shouldn't because we rendered the |
24 // page in view source). | 25 // page in view source). |
25 // Flaky; see http://crbug.com/72201. | 26 // Flaky; see http://crbug.com/72201. |
26 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { | 27 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { |
27 ASSERT_TRUE(test_server()->Start()); | 28 ASSERT_TRUE(test_server()->Start()); |
28 | 29 |
29 // First we navigate to our view-source test page. | 30 // First we navigate to our view-source test page. |
30 GURL url(chrome::kViewSourceScheme + std::string(":") + | 31 GURL url(chrome::kViewSourceScheme + std::string(":") + |
31 test_server()->GetURL(kTestHtml).spec()); | 32 test_server()->GetURL(kTestHtml).spec()); |
32 ui_test_utils::NavigateToURL(browser(), url); | 33 ui_test_utils::NavigateToURL(browser(), url); |
33 | 34 |
34 // Check that the title didn't get set. It should not be there (because we | 35 // Check that the title didn't get set. It should not be there (because we |
35 // are in view-source mode). | 36 // are in view-source mode). |
36 EXPECT_NE(ASCIIToUTF16("foo"), | 37 EXPECT_NE(ASCIIToUTF16("foo"), |
37 browser()->GetActiveWebContents()->GetTitle()); | 38 chrome::GetActiveWebContents(browser())->GetTitle()); |
38 } | 39 } |
39 | 40 |
40 // This test renders a page normally and then renders the same page in | 41 // This test renders a page normally and then renders the same page in |
41 // view-source mode. This is done since we had a problem at one point during | 42 // view-source mode. This is done since we had a problem at one point during |
42 // implementation of the view-source: prefix being consumed (removed from the | 43 // implementation of the view-source: prefix being consumed (removed from the |
43 // URL) if the URL was not changed (apart from adding the view-source prefix) | 44 // URL) if the URL was not changed (apart from adding the view-source prefix) |
44 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { | 45 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { |
45 ASSERT_TRUE(test_server()->Start()); | 46 ASSERT_TRUE(test_server()->Start()); |
46 | 47 |
47 // First we navigate to google.html. | 48 // First we navigate to google.html. |
48 GURL url(test_server()->GetURL(kTestHtml)); | 49 GURL url(test_server()->GetURL(kTestHtml)); |
49 ui_test_utils::NavigateToURL(browser(), url); | 50 ui_test_utils::NavigateToURL(browser(), url); |
50 | 51 |
51 // Then we navigate to the same url but with the "view-source:" prefix. | 52 // Then we navigate to the same url but with the "view-source:" prefix. |
52 GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") + | 53 GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") + |
53 url.spec()); | 54 url.spec()); |
54 ui_test_utils::NavigateToURL(browser(), url_viewsource); | 55 ui_test_utils::NavigateToURL(browser(), url_viewsource); |
55 | 56 |
56 // The URL should still be prefixed with "view-source:". | 57 // The URL should still be prefixed with "view-source:". |
57 EXPECT_EQ(url_viewsource.spec(), | 58 EXPECT_EQ(url_viewsource.spec(), |
58 browser()->GetActiveWebContents()->GetURL().spec()); | 59 chrome::GetActiveWebContents(browser())->GetURL().spec()); |
59 } | 60 } |
60 | 61 |
61 // Make sure that when looking at the actual page, we can select "View Source" | 62 // Make sure that when looking at the actual page, we can select "View Source" |
62 // from the menu. | 63 // from the menu. |
63 IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) { | 64 IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) { |
64 ASSERT_TRUE(test_server()->Start()); | 65 ASSERT_TRUE(test_server()->Start()); |
65 | 66 |
66 GURL url(test_server()->GetURL(kTestHtml)); | 67 GURL url(test_server()->GetURL(kTestHtml)); |
67 ui_test_utils::NavigateToURL(browser(), url); | 68 ui_test_utils::NavigateToURL(browser(), url); |
68 | 69 |
69 EXPECT_TRUE(chrome::CanViewSource(browser())); | 70 EXPECT_TRUE(chrome::CanViewSource(browser())); |
70 } | 71 } |
71 | 72 |
72 // Make sure that when looking at the page source, we can't select "View Source" | 73 // Make sure that when looking at the page source, we can't select "View Source" |
73 // from the menu. | 74 // from the menu. |
74 // | 75 // |
75 // Occasionally crashes on all platforms, see http://crbug.com/69249 | 76 // Occasionally crashes on all platforms, see http://crbug.com/69249 |
76 IN_PROC_BROWSER_TEST_F(ViewSourceTest, | 77 IN_PROC_BROWSER_TEST_F(ViewSourceTest, |
77 ViewSourceInMenuDisabledWhileViewingSource) { | 78 ViewSourceInMenuDisabledWhileViewingSource) { |
78 ASSERT_TRUE(test_server()->Start()); | 79 ASSERT_TRUE(test_server()->Start()); |
79 | 80 |
80 GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") + | 81 GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") + |
81 test_server()->GetURL(kTestHtml).spec()); | 82 test_server()->GetURL(kTestHtml).spec()); |
82 ui_test_utils::NavigateToURL(browser(), url_viewsource); | 83 ui_test_utils::NavigateToURL(browser(), url_viewsource); |
83 | 84 |
84 EXPECT_FALSE(chrome::CanViewSource(browser())); | 85 EXPECT_FALSE(chrome::CanViewSource(browser())); |
85 } | 86 } |
OLD | NEW |