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

Unified Diff: blimp/test/browser_tests/blimp_browser_test.cc

Issue 1929723002: [Blimp] Adds blimp engine browser test framework and LoadUrl test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update gn and deps Created 4 years, 7 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: blimp/test/browser_tests/blimp_browser_test.cc
diff --git a/blimp/test/browser_tests/blimp_browser_test.cc b/blimp/test/browser_tests/blimp_browser_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bcb70947cee2c211017a8915666e387d6b1b4215
--- /dev/null
+++ b/blimp/test/browser_tests/blimp_browser_test.cc
@@ -0,0 +1,122 @@
+// Copyright 2016 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 "blimp/test/browser_tests/blimp_browser_test.h"
+
+#include <string>
+
+#include "base/base_switches.h"
+#include "base/command_line.h"
+#include "base/files/file_path.h"
+#include "base/memory/ptr_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "blimp/client/app/blimp_client_switches.h"
+#include "blimp/client/session/assignment_source.h"
+#include "blimp/engine/app/blimp_browser_main_parts.h"
+#include "blimp/engine/app/blimp_content_browser_client.h"
+#include "blimp/engine/app/blimp_content_main_delegate.h"
+#include "blimp/engine/app/blimp_engine_config.h"
+#include "blimp/engine/app/switches.h"
+#include "blimp/engine/session/blimp_engine_session.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/common/url_constants.h"
+
+namespace blimp {
+namespace {
+const char kTestDataFilePath[] = "blimp/engine/test/data";
+const char kClientTokenFilePath[] = "blimp/test/data/test_client_token";
+} // namespace
+
+BlimpBrowserTest::BlimpBrowserTest() {
+ base::FilePath test_data(FILE_PATH_LITERAL(kTestDataFilePath));
+ CreateTestServer(test_data);
Kevin M 2016/05/05 20:28:51 Just put FILE_PATH_LITERAL inline, no need to make
haibinlu 2016/05/05 22:41:36 Done.
+}
+
+BlimpBrowserTest::~BlimpBrowserTest() {}
+
+void BlimpBrowserTest::SetUp() {
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ SetUpCommandLine(command_line);
+ BrowserTestBase::SetUp();
Kevin M 2016/05/05 20:28:51 Does this need to come after the BlimpBrowserTest
haibinlu 2016/05/05 22:41:36 No, it should be called after our command line is
+}
+
+engine::BlimpEngineSession* BlimpBrowserTest::GetEngineSession() {
+ return engine::BlimpContentMainDelegate::GetInstanceForTesting()
+ ->GetBlimpContentBrowserClient()
+ ->blimp_browser_main_parts()
+ ->GetBlimpEngineSession();
+}
+
+void BlimpBrowserTest::OnGetEnginePort(uint16_t port) {
+ DCHECK_GT(port, 0);
+ // A test Client is started after BlimpBrowserTest::SetUpOnMainThread()
Kevin M 2016/05/05 20:28:51 lowercase C, trailing period, newline before comme
haibinlu 2016/05/05 22:41:36 Done.
+ engine_port_ = port;
+ QuitRunLoop();
+}
+
+client::Assignment BlimpBrowserTest::GetClientAssignment() {
Kevin M 2016/05/05 20:28:51 We just call them "assignments", so how about GetA
haibinlu 2016/05/05 22:41:36 Done.
+ client::Assignment assignment;
+ assignment.client_token = client::kDummyClientToken;
+ assignment.engine_endpoint =
+ net::IPEndPoint(net::IPAddress::IPv4Localhost(), engine_port_);
+ assignment.transport_protocol = client::Assignment::TransportProtocol::TCP;
+ return assignment;
+}
+
+void BlimpBrowserTest::SetUpOnMainThread() {
+ GetEngineSession()->GetEnginePortForTesting(
+ base::Bind(&BlimpBrowserTest::OnGetEnginePort, base::Unretained(this)));
+ RunUntilQuit();
+}
+
+void BlimpBrowserTest::TearDownOnMainThread() {
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI)
+ ->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
+}
+
+void BlimpBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
+ command_line->AppendSwitchASCII(::switches::kVModule, "blimp*=2");
Kevin M 2016/05/05 20:28:51 This will make the test output very noisy. We shou
haibinlu 2016/05/05 22:41:36 removed
+
+ // Engine switches
Kevin M 2016/05/05 20:28:51 trailing period
+ blimp::engine::SetUpCommandLine(command_line);
+ // Use dynamically allocated port for browser test.
Kevin M 2016/05/05 20:28:51 Newline before comment
haibinlu 2016/05/05 22:41:36 Done.
+ command_line->AppendSwitchASCII(blimp::engine::kEnginePort, "0");
+ command_line->AppendSwitchASCII(blimp::engine::kClientTokenPath,
+ kClientTokenFilePath);
+}
+
+void BlimpBrowserTest::RunTestOnMainThreadLoop() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ // Pump startup related events.
+ base::MessageLoop::current()->RunUntilIdle();
+
+ SetUpOnMainThread();
+ RunTestOnMainThread();
+ TearDownOnMainThread();
+
+ for (content::RenderProcessHost::iterator i(
+ content::RenderProcessHost::AllHostsIterator());
+ !i.IsAtEnd(); i.Advance()) {
+ i.GetCurrentValue()->FastShutdownIfPossible();
+ }
+}
+
+void BlimpBrowserTest::RunUntilQuit() {
+ base::MessageLoop::ScopedNestableTaskAllower nestable_allower(
+ base::MessageLoop::current());
+ EXPECT_FALSE(run_loop_);
+ run_loop_ = base::WrapUnique(new base::RunLoop());
+ run_loop_->Run();
+ run_loop_ = nullptr;
+}
+
+void BlimpBrowserTest::QuitRunLoop() {
Kevin M 2016/05/05 20:28:51 This function is too trivial, we should just make
haibinlu 2016/05/05 22:41:36 IN_PROC_BROWSER_TEST_F(EngineBrowserTest, LoadUrl)
+ run_loop_->Quit();
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698