This source file includes following definitions.
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/strings/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
namespace {
const char kTestHtml[] = "/viewsource/test.html";
const char kTestMedia[] = "files/media/pink_noise_140ms.wav";
}
typedef InProcessBrowserTest ViewSourceTest;
IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL url(content::kViewSourceScheme + std::string(":") +
embedded_test_server()->GetURL(kTestHtml).spec());
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_NE(base::ASCIIToUTF16("foo"),
browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
}
IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL url(embedded_test_server()->GetURL(kTestHtml));
ui_test_utils::NavigateToURL(browser(), url);
GURL url_viewsource(content::kViewSourceScheme + std::string(":") +
url.spec());
ui_test_utils::NavigateToURL(browser(), url_viewsource);
EXPECT_EQ(url_viewsource.spec(),
browser()->tab_strip_model()->GetActiveWebContents()->
GetURL().spec());
}
IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL url(embedded_test_server()->GetURL(kTestHtml));
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_TRUE(chrome::CanViewSource(browser()));
}
IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceInMenuDisabledOnAMediaPage) {
ASSERT_TRUE(test_server()->Start());
GURL url(test_server()->GetURL(kTestMedia));
ui_test_utils::NavigateToURL(browser(), url);
const char* mime_type = browser()->tab_strip_model()->GetActiveWebContents()->
GetContentsMimeType().c_str();
EXPECT_STREQ("audio/wav", mime_type);
EXPECT_FALSE(chrome::CanViewSource(browser()));
}
IN_PROC_BROWSER_TEST_F(ViewSourceTest,
ViewSourceInMenuDisabledWhileViewingSource) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL url_viewsource(content::kViewSourceScheme + std::string(":") +
embedded_test_server()->GetURL(kTestHtml).spec());
ui_test_utils::NavigateToURL(browser(), url_viewsource);
EXPECT_FALSE(chrome::CanViewSource(browser()));
}
IN_PROC_BROWSER_TEST_F(ViewSourceTest, DISABLED_TestViewSourceReload) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
GURL url_viewsource(content::kViewSourceScheme + std::string(":") +
embedded_test_server()->GetURL(kTestHtml).spec());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
ui_test_utils::NavigateToURL(browser(), url_viewsource);
observer.Wait();
ASSERT_TRUE(
content::ExecuteScript(browser()->tab_strip_model()->GetWebContentsAt(0),
"window.location.reload();"));
content::WindowedNotificationObserver observer2(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
observer2.Wait();
ASSERT_TRUE(browser()->tab_strip_model()->GetWebContentsAt(0)->
GetController().GetActiveEntry()->IsViewSourceMode());
}