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 @@
'test/base/history_index_restore_observer.h',
'test/base/in_process_browser_test.cc',
'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.h',
'test/base/profile_mock.cc',
......
......@@ -20,7 +20,7 @@
#include "content/public/common/webplugininfo.h"
#include "net/base/net_util.h"
typedef TestMessageHandler::MessageResponse MessageResponse;
typedef content::TestMessageHandler::MessageResponse MessageResponse;
MessageResponse StructuredMessageHandler::HandleMessage(
const std::string& json) {
......@@ -234,9 +234,10 @@ GURL NaClBrowserTestBase::TestURL(
return test_server_->GetURL(expanded_url.MaybeAsASCII());
}
bool NaClBrowserTestBase::RunJavascriptTest(const GURL& url,
TestMessageHandler* handler) {
JavascriptTestObserver observer(
bool NaClBrowserTestBase::RunJavascriptTest(
const GURL& url,
content::TestMessageHandler* handler) {
content::JavascriptTestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents(),
handler);
ui_test_utils::NavigateToURL(browser(), url);
......
......@@ -8,11 +8,11 @@
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.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:
// {"type": type_name, ...}
class StructuredMessageHandler : public TestMessageHandler {
class StructuredMessageHandler : public content::TestMessageHandler {
public:
virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE;
......@@ -85,7 +85,7 @@ class NaClBrowserTestBase : public InProcessBrowserTest {
// Load a URL and listen to automation events with a given handler.
// Returns true if the test glue function correctly. (The handler should
// 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
// setting up other tests, such as checking that UMA data was logged.
......
......@@ -42,7 +42,7 @@ void PnaclHeaderTest::RunLoadTest(const std::string& url,
int expected_cors) {
StartServer();
LoadTestMessageHandler handler;
JavascriptTestObserver observer(
content::JavascriptTestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents(),
&handler);
ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(url));
......
......@@ -11,11 +11,11 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.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/nacl/nacl_browsertest_util.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/javascript_test_observer.h"
#include "content/public/test/test_renderer_host.h"
using content::RenderViewHost;
......@@ -1205,7 +1205,7 @@ IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, View_CreateInvisible) {
IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, View_PageHideShow) {
// The plugin will be loaded in the foreground tab and will send us a message.
PPAPITestMessageHandler handler;
JavascriptTestObserver observer(
content::JavascriptTestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents(),
&handler);
......
......@@ -33,6 +33,7 @@
using content::DomOperationNotificationDetails;
using content::RenderViewHost;
using content::TestMessageHandler;
namespace {
......@@ -280,7 +281,7 @@ void PPAPITestBase::RunTestURL(const GURL& test_url) {
// 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.
PPAPITestMessageHandler handler;
JavascriptTestObserver observer(
content::JavascriptTestObserver observer(
browser()->tab_strip_model()->GetActiveWebContents(),
&handler);
......
......@@ -10,19 +10,18 @@
#include "base/basictypes.h"
#include "base/compiler_specific.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"
namespace content {
class RenderViewHost;
}
class PPAPITestMessageHandler : public TestMessageHandler {
class PPAPITestMessageHandler : public content::TestMessageHandler {
public:
PPAPITestMessageHandler();
MessageResponse HandleMessage(const std::string& json);
virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE;
virtual void Reset() OVERRIDE;
const std::string& message() const {
......
......@@ -83,6 +83,8 @@
'public/test/download_test_observer.h',
'public/test/fake_speech_recognition_manager.cc',
'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.h',
'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
// 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/notification_types.h"
......@@ -10,6 +10,8 @@
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_utils.h"
namespace content {
TestMessageHandler::TestMessageHandler() : ok_(true) {
}
......@@ -27,15 +29,14 @@ void TestMessageHandler::Reset() {
}
JavascriptTestObserver::JavascriptTestObserver(
content::WebContents* web_contents,
TestMessageHandler* handler)
WebContents* web_contents, TestMessageHandler* handler)
: handler_(handler),
running_(false),
finished_(false) {
Reset();
registrar_.Add(this,
content::NOTIFICATION_DOM_OPERATION_RESPONSE,
content::Source<content::WebContents>(web_contents));
NOTIFICATION_DOM_OPERATION_RESPONSE,
Source<WebContents>(web_contents));
}
JavascriptTestObserver::~JavascriptTestObserver() {
......@@ -46,7 +47,7 @@ bool JavascriptTestObserver::Run() {
if (!finished_) {
CHECK(!running_);
running_ = true;
content::RunMessageLoop();
RunMessageLoop();
running_ = false;
}
return handler_->ok();
......@@ -61,11 +62,10 @@ void JavascriptTestObserver::Reset() {
void JavascriptTestObserver::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
CHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE);
content::Details<content::DomOperationNotificationDetails> dom_op_details(
details);
const NotificationSource& source,
const NotificationDetails& details) {
CHECK(type == NOTIFICATION_DOM_OPERATION_RESPONSE);
Details<DomOperationNotificationDetails> dom_op_details(details);
// We might receive responses for other script execution, but we only
// care about the test finished message.
TestMessageHandler::MessageResponse response =
......@@ -88,3 +88,5 @@ void JavascriptTestObserver::EndTest() {
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
// found in the LICENSE file.
#ifndef CHROME_TEST_BASE_JAVASCRIPT_TEST_OBSERVER_H_
#define CHROME_TEST_BASE_JAVASCRIPT_TEST_OBSERVER_H_
#ifndef CONTENT_PUBLIC_TEST_JAVASCRIPT_TEST_OBSERVER_H_
#define CONTENT_PUBLIC_TEST_JAVASCRIPT_TEST_OBSERVER_H_
#include <string>
......@@ -17,7 +17,6 @@ class DictionaryValue;
namespace content {
class WebContents;
}
// Base class for handling a stream of automation messages produced by a
// JavascriptTestObserver.
......@@ -56,13 +55,12 @@ class TestMessageHandler {
// This class captures a stream of automation messages coming from a Javascript
// test and dispatches them to a message handler.
class JavascriptTestObserver : public content::NotificationObserver {
class JavascriptTestObserver : public NotificationObserver {
public:
// The observer does not own any arguments passed to it. It is assumed that
// the arguments will outlive all uses of the observer.
JavascriptTestObserver(
content::WebContents* web_contents,
TestMessageHandler* handler);
JavascriptTestObserver(WebContents* web_contents,
TestMessageHandler* handler);
virtual ~JavascriptTestObserver();
......@@ -77,8 +75,8 @@ class JavascriptTestObserver : public content::NotificationObserver {
virtual void Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
const NotificationSource& source,
const NotificationDetails& details) OVERRIDE;
private:
// This message did not signal the end of a test, keep going.
......@@ -90,9 +88,11 @@ class JavascriptTestObserver : public content::NotificationObserver {
TestMessageHandler* handler_;
bool running_;
bool finished_;
content::NotificationRegistrar registrar_;
NotificationRegistrar registrar_;
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