Commit e4c3a397 authored by teravest@chromium.org's avatar teravest@chromium.org

Move JavascriptTestObserver from chrome to content.

This change moves the test support class JavascriptTestObserver from
chrome/test to content/public/test. This test doesn't have any dependencies on
anything in chrome/, and moving it will allow tests in content to use this
utility class.

This class has to move to content to allow moving some Pepper testing from
chrome/ to content/

BUG=371873

Review URL: https://codereview.chromium.org/286243003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271209 0039d316-1c4b-4281-b951-d872f2087c98
parent 850aacb9
...@@ -233,8 +233,6 @@ ...@@ -233,8 +233,6 @@
'test/base/history_index_restore_observer.h', 'test/base/history_index_restore_observer.h',
'test/base/in_process_browser_test.cc', 'test/base/in_process_browser_test.cc',
'test/base/in_process_browser_test.h', 'test/base/in_process_browser_test.h',
'test/base/javascript_test_observer.cc',
'test/base/javascript_test_observer.h',
'test/base/module_system_test.cc', 'test/base/module_system_test.cc',
'test/base/module_system_test.h', 'test/base/module_system_test.h',
'test/base/profile_mock.cc', 'test/base/profile_mock.cc',
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "content/public/common/webplugininfo.h" #include "content/public/common/webplugininfo.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
typedef TestMessageHandler::MessageResponse MessageResponse; typedef content::TestMessageHandler::MessageResponse MessageResponse;
MessageResponse StructuredMessageHandler::HandleMessage( MessageResponse StructuredMessageHandler::HandleMessage(
const std::string& json) { const std::string& json) {
...@@ -234,9 +234,10 @@ GURL NaClBrowserTestBase::TestURL( ...@@ -234,9 +234,10 @@ GURL NaClBrowserTestBase::TestURL(
return test_server_->GetURL(expanded_url.MaybeAsASCII()); return test_server_->GetURL(expanded_url.MaybeAsASCII());
} }
bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url, bool NaClBrowserTestBase::RunJavascriptTest(
TestMessageHandler* handler) { const GURL& url,
JavascriptTestObserver observer( content::TestMessageHandler* handler) {
content::JavascriptTestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
handler); handler);
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/javascript_test_observer.h" #include "content/public/test/javascript_test_observer.h"
// A helper base class that decodes structured automation messages of the form: // A helper base class that decodes structured automation messages of the form:
// {"type": type_name, ...} // {"type": type_name, ...}
class StructuredMessageHandler : public TestMessageHandler { class StructuredMessageHandler : public content::TestMessageHandler {
public: public:
virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE; virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE;
...@@ -85,7 +85,7 @@ class NaClBrowserTestBase : public InProcessBrowserTest { ...@@ -85,7 +85,7 @@ class NaClBrowserTestBase : public InProcessBrowserTest {
// Load a URL and listen to automation events with a given handler. // Load a URL and listen to automation events with a given handler.
// Returns true if the test glue function correctly. (The handler should // Returns true if the test glue function correctly. (The handler should
// seperately indicate if the test failed.) // seperately indicate if the test failed.)
bool RunJavascriptTest(const GURL& url, TestMessageHandler* handler); bool RunJavascriptTest(const GURL& url, content::TestMessageHandler* handler);
// Run a simple test that checks that a nexe loads correctly. Useful for // Run a simple test that checks that a nexe loads correctly. Useful for
// setting up other tests, such as checking that UMA data was logged. // setting up other tests, such as checking that UMA data was logged.
......
...@@ -42,7 +42,7 @@ void PnaclHeaderTest::RunLoadTest(const std::string& url, ...@@ -42,7 +42,7 @@ void PnaclHeaderTest::RunLoadTest(const std::string& url,
int expected_cors) { int expected_cors) {
StartServer(); StartServer();
LoadTestMessageHandler handler; LoadTestMessageHandler handler;
JavascriptTestObserver observer( content::JavascriptTestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
&handler); &handler);
ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(url)); ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(url));
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/javascript_test_observer.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/nacl/nacl_browsertest_util.h" #include "chrome/test/nacl/nacl_browsertest_util.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/test/javascript_test_observer.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
using content::RenderViewHost; using content::RenderViewHost;
...@@ -1205,7 +1205,7 @@ IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, View_CreateInvisible) { ...@@ -1205,7 +1205,7 @@ IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, View_CreateInvisible) {
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, View_PageHideShow) { IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, View_PageHideShow) {
// The plugin will be loaded in the foreground tab and will send us a message. // The plugin will be loaded in the foreground tab and will send us a message.
PPAPITestMessageHandler handler; PPAPITestMessageHandler handler;
JavascriptTestObserver observer( content::JavascriptTestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
&handler); &handler);
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
using content::DomOperationNotificationDetails; using content::DomOperationNotificationDetails;
using content::RenderViewHost; using content::RenderViewHost;
using content::TestMessageHandler;
namespace { namespace {
...@@ -280,7 +281,7 @@ void PPAPITestBase::RunTestURL(const GURL& test_url) { ...@@ -280,7 +281,7 @@ void PPAPITestBase::RunTestURL(const GURL& test_url) {
// any other value indicates completion (in this case it will start with // any other value indicates completion (in this case it will start with
// "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests.
PPAPITestMessageHandler handler; PPAPITestMessageHandler handler;
JavascriptTestObserver observer( content::JavascriptTestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents(), browser()->tab_strip_model()->GetActiveWebContents(),
&handler); &handler);
......
...@@ -10,19 +10,18 @@ ...@@ -10,19 +10,18 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/javascript_test_observer.h" #include "content/public/test/javascript_test_observer.h"
#include "net/test/spawned_test_server/spawned_test_server.h" #include "net/test/spawned_test_server/spawned_test_server.h"
namespace content { namespace content {
class RenderViewHost; class RenderViewHost;
} }
class PPAPITestMessageHandler : public TestMessageHandler { class PPAPITestMessageHandler : public content::TestMessageHandler {
public: public:
PPAPITestMessageHandler(); PPAPITestMessageHandler();
MessageResponse HandleMessage(const std::string& json); virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE;
virtual void Reset() OVERRIDE; virtual void Reset() OVERRIDE;
const std::string& message() const { const std::string& message() const {
......
...@@ -83,6 +83,8 @@ ...@@ -83,6 +83,8 @@
'public/test/download_test_observer.h', 'public/test/download_test_observer.h',
'public/test/fake_speech_recognition_manager.cc', 'public/test/fake_speech_recognition_manager.cc',
'public/test/fake_speech_recognition_manager.h', 'public/test/fake_speech_recognition_manager.h',
'public/test/javascript_test_observer.cc',
'public/test/javascript_test_observer.h',
'public/test/mock_blob_url_request_context.cc', 'public/test/mock_blob_url_request_context.cc',
'public/test/mock_blob_url_request_context.h', 'public/test/mock_blob_url_request_context.h',
'public/test/mock_download_item.cc', 'public/test/mock_download_item.cc',
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/test/base/javascript_test_observer.h" #include "content/public/test/javascript_test_observer.h"
#include "content/public/browser/dom_operation_notification_details.h" #include "content/public/browser/dom_operation_notification_details.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
namespace content {
TestMessageHandler::TestMessageHandler() : ok_(true) { TestMessageHandler::TestMessageHandler() : ok_(true) {
} }
...@@ -27,15 +29,14 @@ void TestMessageHandler::Reset() { ...@@ -27,15 +29,14 @@ void TestMessageHandler::Reset() {
} }
JavascriptTestObserver::JavascriptTestObserver( JavascriptTestObserver::JavascriptTestObserver(
content::WebContents* web_contents, WebContents* web_contents, TestMessageHandler* handler)
TestMessageHandler* handler)
: handler_(handler), : handler_(handler),
running_(false), running_(false),
finished_(false) { finished_(false) {
Reset(); Reset();
registrar_.Add(this, registrar_.Add(this,
content::NOTIFICATION_DOM_OPERATION_RESPONSE, NOTIFICATION_DOM_OPERATION_RESPONSE,
content::Source<content::WebContents>(web_contents)); Source<WebContents>(web_contents));
} }
JavascriptTestObserver::~JavascriptTestObserver() { JavascriptTestObserver::~JavascriptTestObserver() {
...@@ -46,7 +47,7 @@ bool JavascriptTestObserver::Run() { ...@@ -46,7 +47,7 @@ bool JavascriptTestObserver::Run() {
if (!finished_) { if (!finished_) {
CHECK(!running_); CHECK(!running_);
running_ = true; running_ = true;
content::RunMessageLoop(); RunMessageLoop();
running_ = false; running_ = false;
} }
return handler_->ok(); return handler_->ok();
...@@ -61,11 +62,10 @@ void JavascriptTestObserver::Reset() { ...@@ -61,11 +62,10 @@ void JavascriptTestObserver::Reset() {
void JavascriptTestObserver::Observe( void JavascriptTestObserver::Observe(
int type, int type,
const content::NotificationSource& source, const NotificationSource& source,
const content::NotificationDetails& details) { const NotificationDetails& details) {
CHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE); CHECK(type == NOTIFICATION_DOM_OPERATION_RESPONSE);
content::Details<content::DomOperationNotificationDetails> dom_op_details( Details<DomOperationNotificationDetails> dom_op_details(details);
details);
// We might receive responses for other script execution, but we only // We might receive responses for other script execution, but we only
// care about the test finished message. // care about the test finished message.
TestMessageHandler::MessageResponse response = TestMessageHandler::MessageResponse response =
...@@ -88,3 +88,5 @@ void JavascriptTestObserver::EndTest() { ...@@ -88,3 +88,5 @@ void JavascriptTestObserver::EndTest() {
base::MessageLoopForUI::current()->Quit(); base::MessageLoopForUI::current()->Quit();
} }
} }
} // namespace content
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_TEST_BASE_JAVASCRIPT_TEST_OBSERVER_H_ #ifndef CONTENT_PUBLIC_TEST_JAVASCRIPT_TEST_OBSERVER_H_
#define CHROME_TEST_BASE_JAVASCRIPT_TEST_OBSERVER_H_ #define CONTENT_PUBLIC_TEST_JAVASCRIPT_TEST_OBSERVER_H_
#include <string> #include <string>
...@@ -17,7 +17,6 @@ class DictionaryValue; ...@@ -17,7 +17,6 @@ class DictionaryValue;
namespace content { namespace content {
class WebContents; class WebContents;
}
// Base class for handling a stream of automation messages produced by a // Base class for handling a stream of automation messages produced by a
// JavascriptTestObserver. // JavascriptTestObserver.
...@@ -56,12 +55,11 @@ class TestMessageHandler { ...@@ -56,12 +55,11 @@ class TestMessageHandler {
// This class captures a stream of automation messages coming from a Javascript // This class captures a stream of automation messages coming from a Javascript
// test and dispatches them to a message handler. // test and dispatches them to a message handler.
class JavascriptTestObserver : public content::NotificationObserver { class JavascriptTestObserver : public NotificationObserver {
public: public:
// The observer does not own any arguments passed to it. It is assumed that // The observer does not own any arguments passed to it. It is assumed that
// the arguments will outlive all uses of the observer. // the arguments will outlive all uses of the observer.
JavascriptTestObserver( JavascriptTestObserver(WebContents* web_contents,
content::WebContents* web_contents,
TestMessageHandler* handler); TestMessageHandler* handler);
virtual ~JavascriptTestObserver(); virtual ~JavascriptTestObserver();
...@@ -77,8 +75,8 @@ class JavascriptTestObserver : public content::NotificationObserver { ...@@ -77,8 +75,8 @@ class JavascriptTestObserver : public content::NotificationObserver {
virtual void Observe( virtual void Observe(
int type, int type,
const content::NotificationSource& source, const NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE; const NotificationDetails& details) OVERRIDE;
private: private:
// This message did not signal the end of a test, keep going. // This message did not signal the end of a test, keep going.
...@@ -90,9 +88,11 @@ class JavascriptTestObserver : public content::NotificationObserver { ...@@ -90,9 +88,11 @@ class JavascriptTestObserver : public content::NotificationObserver {
TestMessageHandler* handler_; TestMessageHandler* handler_;
bool running_; bool running_;
bool finished_; bool finished_;
content::NotificationRegistrar registrar_; NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(JavascriptTestObserver); DISALLOW_COPY_AND_ASSIGN(JavascriptTestObserver);
}; };
#endif // CHROME_TEST_BASE_JAVASCRIPT_TEST_OBSERVER_H_ } // namespace content
#endif // CONTENT_PUBLIC_TEST_JAVASCRIPT_TEST_OBSERVER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment