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

Unified Diff: chrome/browser/ui/webui/net_internals_ui_browsertest.cc

Issue 7553009: Add some browser tests for net-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix test_view.js Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/net_internals_ui_browsertest.cc
===================================================================
--- chrome/browser/ui/webui/net_internals_ui_browsertest.cc (revision 0)
+++ chrome/browser/ui/webui/net_internals_ui_browsertest.cc (revision 0)
@@ -0,0 +1,235 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/webui/web_ui_browsertest.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "googleurl/src/gurl.h"
+#include "net/base/net_errors.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// Each test involves calls a single Javascript function and then waits for the
+// title to be changed to "Test Passed" or "Test Failed" when done.
+class NetInternalsTest : public WebUIBrowserTest {
+ public:
+ NetInternalsTest();
+ virtual ~NetInternalsTest();
+
+ // InProcessBrowserTest overrides.
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
+ virtual void SetUpOnMainThread() OVERRIDE;
+
+
+ // Runs the specified Javascript test function with the specified arguments
+ // and waits for the title to change to "Test Passed" or "Test Failed".
+ void RunTestAndWaitForTitle(const std::string& function_name,
+ const ListValue& function_arguments);
+
+ // Same as above, with constant number of arguments for easy use. Will also
+ // free arguments.
+ void RunTestAndWaitForTitle(const std::string& function_name);
+ void RunTestAndWaitForTitle(const std::string& function_name, Value* arg);
+ void RunTestAndWaitForTitle(const std::string& function_name,
+ Value* arg1, Value* arg2);
+ void RunTestAndWaitForTitle(const std::string& function_name,
+ Value* arg1, Value* arg2, Value* arg3);
+
+ void set_expect_success_(bool value) { expect_success_ = value; }
+
+ private:
+ // True if the test is expected to pass. Default value is true. Set to false
+ // on some tests of the test infrastructure.
+ bool expect_success_;
+};
+
+NetInternalsTest::NetInternalsTest() : expect_success_(true) {
+}
+
+NetInternalsTest::~NetInternalsTest() {
+}
+
+void NetInternalsTest::SetUpCommandLine(CommandLine* command_line) {
+ WebUIBrowserTest::SetUpCommandLine(command_line);
+ // Needed to test the prerender view.
+ command_line->AppendSwitchASCII(switches::kPrerender,
+ switches::kPrerenderSwitchValueEnabled);
+}
+
+void NetInternalsTest::SetUpInProcessBrowserTestFixture() {
+ WebUIBrowserTest::SetUpInProcessBrowserTestFixture();
+
+ // Add Javascript files needed for the tests. Must be added after
+ // WebUIBrowserTest adds its files.
+ AddLibrary(FilePath(FILE_PATH_LITERAL("net_internals/framework.js")));
+
+ AddLibrary(FilePath(FILE_PATH_LITERAL("net_internals/log_view_painter.js")));
+ AddLibrary(FilePath(FILE_PATH_LITERAL("net_internals/prerender_view.js")));
+ AddLibrary(FilePath(FILE_PATH_LITERAL("net_internals/test_view.js")));
+}
+
+void NetInternalsTest::SetUpOnMainThread() {
+ // Navigate to the net-internals page.
+ ui_test_utils::NavigateToURL(browser(),
+ GURL(chrome::kChromeUINetInternalsURL));
+}
+
+void NetInternalsTest::RunTestAndWaitForTitle(
+ const std::string& function_name,
+ const ListValue& function_arguments) {
+ ui_test_utils::TitleWatcher title_watcher(browser()->GetTabContentsAt(0),
+ ASCIIToUTF16("Test Passed"),
+ ASCIIToUTF16("Test Failed"));
+
+ ConstValueVector arguments;
+ StringValue function_name_arg(function_name);
+ arguments.push_back(&function_name_arg);
+ arguments.push_back(&function_arguments);
+
+ ASSERT_TRUE(RunJavascriptFunction("runNetInternalsTest", arguments));
+ ASSERT_EQ(expect_success_, title_watcher.Wait());
+}
+
+void NetInternalsTest::RunTestAndWaitForTitle(
+ const std::string& function_name) {
+ ListValue test_arguments;
+ RunTestAndWaitForTitle(function_name, test_arguments);
+}
+
+void NetInternalsTest::RunTestAndWaitForTitle(const std::string& function_name,
+ Value* arg) {
+ ListValue test_arguments;
+ test_arguments.Append(arg);
+ RunTestAndWaitForTitle(function_name, test_arguments);
+}
+
+void NetInternalsTest::RunTestAndWaitForTitle(const std::string& function_name,
+ Value* arg1, Value* arg2) {
+ ListValue test_arguments;
+ test_arguments.Append(arg1);
+ test_arguments.Append(arg2);
+ RunTestAndWaitForTitle(function_name, test_arguments);
+}
+
+void NetInternalsTest::RunTestAndWaitForTitle(const std::string& function_name,
+ Value* arg1, Value* arg2,
+ Value* arg3) {
+ ListValue test_arguments;
+ test_arguments.Append(arg1);
+ test_arguments.Append(arg2);
+ test_arguments.Append(arg3);
+ RunTestAndWaitForTitle(function_name, test_arguments);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// framework.js
+////////////////////////////////////////////////////////////////////////////////
+
+// Checks testDone.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsDone) {
+ RunTestAndWaitForTitle("NetInternalsDone");
+}
+
+// Checks a failed expect statement.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsExpectFail) {
+ set_expect_success_(false);
+ RunTestAndWaitForTitle("NetInternalsExpectFail");
+}
+
+// Checks a failed assert statement.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsAssertFail) {
+ set_expect_success_(false);
+ RunTestAndWaitForTitle("NetInternalsAssertFail");
+}
+
+// Checks that testDone works when called by an observer in response to an
+// event.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsObserverDone) {
+ RunTestAndWaitForTitle("NetInternalsObserverDone");
+}
+
+// Checks that a failed expect works when called by an observer in response
+// to an event.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsObserverExpectFail) {
+ set_expect_success_(false);
+ RunTestAndWaitForTitle("NetInternalsObserverExpectFail");
+}
+
+// Checks that a failed assertion works when called by an observer in response
+// to an event.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsObserverAssertFail) {
+ set_expect_success_(false);
+ RunTestAndWaitForTitle("NetInternalsObserverAssertFail");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// test_view.js
+////////////////////////////////////////////////////////////////////////////////
+
+// Runs the test suite twice, expecting a passing result each time. Checks
+// the result, the order of events that occur, and the number of rows in the
+// table.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsTestViewPassTwice) {
+ ASSERT_TRUE(test_server()->Start());
+ RunTestAndWaitForTitle(
+ "NetInternalsTestView",
+ // URL that results in success.
+ Value::CreateStringValue(
+ test_server()->GetURL("files/title1.html").spec()),
+ // Resulting error code.
+ Value::CreateIntegerValue(net::OK),
+ // Number of times to run the test.
+ Value::CreateIntegerValue(2));
+}
+
+// Runs the test suite twice, expecting a failing result each time. Checks
+// the result, the order of events that occur, and the number of rows in the
+// table.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsTestViewFailTwice) {
+ RunTestAndWaitForTitle(
+ "NetInternalsTestView",
+ // URL that results in an error, due to the port.
+ Value::CreateStringValue("http://127.0.0.1:7/"),
+ // Resulting error code.
+ Value::CreateIntegerValue(net::ERR_UNSAFE_PORT),
+ // Number of times to run the test.
+ Value::CreateIntegerValue(2));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// prerender_view.js
+////////////////////////////////////////////////////////////////////////////////
+
+// Prerender two pages and check PrerenderView behavior. The first is expected
+// to fail, the second is expected to succeed.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsPrerenderView) {
+ ASSERT_TRUE(test_server()->Start());
+ RunTestAndWaitForTitle(
+ "NetInternalsPrerenderView",
+ // URL that can't be prerendered, since it triggers a download.
+ Value::CreateStringValue(
+ test_server()->GetURL("files/download-test1.lib").spec()),
+ // URL that can be prerendered.
+ Value::CreateStringValue(
+ test_server()->GetURL("files/title1.html").spec()));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// log_view_painter.js
+////////////////////////////////////////////////////////////////////////////////
+
+// Check that we correctly remove cookies and login information.
+IN_PROC_BROWSER_TEST_F(NetInternalsTest,
+ NetInternalsLogViewPainterStripInfo) {
+ RunTestAndWaitForTitle("NetInternalsLogViewPainterStripInfo");
+}
+
+} // namespace
Property changes on: chrome\browser\ui\webui\net_internals_ui_browsertest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698