| Index: content/browser/devtools/devtools_manager_unittest.cc
|
| diff --git a/content/browser/devtools/devtools_manager_unittest.cc b/content/browser/devtools/devtools_manager_unittest.cc
|
| index 08d778ada10193cd785e47474cd74e3cbcf34811..1da4418cbdaa148d5c4748478caa5497be05e097 100644
|
| --- a/content/browser/devtools/devtools_manager_unittest.cc
|
| +++ b/content/browser/devtools/devtools_manager_unittest.cc
|
| @@ -6,19 +6,13 @@
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/time/time.h"
|
| #include "content/browser/devtools/devtools_manager.h"
|
| -#include "content/browser/devtools/embedded_worker_devtools_manager.h"
|
| #include "content/browser/devtools/render_view_devtools_agent_host.h"
|
| -#include "content/browser/shared_worker/shared_worker_instance.h"
|
| -#include "content/browser/shared_worker/worker_storage_partition.h"
|
| #include "content/common/view_messages.h"
|
| -#include "content/public/browser/browser_context.h"
|
| #include "content/public/browser/content_browser_client.h"
|
| #include "content/public/browser/devtools_agent_host.h"
|
| #include "content/public/browser/devtools_external_agent_proxy.h"
|
| #include "content/public/browser/devtools_external_agent_proxy_delegate.h"
|
| -#include "content/public/browser/devtools_target.h"
|
| #include "content/public/browser/web_contents_delegate.h"
|
| -#include "content/public/test/test_utils.h"
|
| #include "content/test/test_content_browser_client.h"
|
| #include "content/test/test_render_view_host.h"
|
| #include "content/test/test_web_contents.h"
|
| @@ -99,122 +93,14 @@
|
| bool renderer_unresponsive_received_;
|
| };
|
|
|
| -class TestTarget : public DevToolsTarget {
|
| - public:
|
| - explicit TestTarget(scoped_refptr<DevToolsAgentHost> agent_host)
|
| - : agent_host_(agent_host) {}
|
| - virtual ~TestTarget() {}
|
| -
|
| - virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); }
|
| - virtual std::string GetParentId() const OVERRIDE { return std::string(); }
|
| - virtual std::string GetType() const OVERRIDE { return std::string(); }
|
| - virtual std::string GetTitle() const OVERRIDE {
|
| - return agent_host_->GetTitle();
|
| - }
|
| - virtual std::string GetDescription() const OVERRIDE { return std::string(); }
|
| - virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); }
|
| - virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); }
|
| - virtual base::TimeTicks GetLastActivityTime() const OVERRIDE {
|
| - return base::TimeTicks();
|
| - }
|
| - virtual bool IsAttached() const OVERRIDE { return agent_host_->IsAttached(); }
|
| - virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE {
|
| - return agent_host_;
|
| - }
|
| - virtual bool Activate() const OVERRIDE { return agent_host_->Activate(); }
|
| - virtual bool Close() const OVERRIDE { return agent_host_->Close(); }
|
| -
|
| - private:
|
| - scoped_refptr<DevToolsAgentHost> agent_host_;
|
| -};
|
| -
|
| -class TestDevToolsManagerDelegate : public DevToolsManagerDelegate {
|
| - public:
|
| - virtual ~TestDevToolsManagerDelegate() {}
|
| -
|
| - virtual void Inspect(BrowserContext* browser_context,
|
| - DevToolsAgentHost* agent_host) OVERRIDE {}
|
| -
|
| - virtual void DevToolsAgentStateChanged(DevToolsAgentHost* agent_host,
|
| - bool attached) OVERRIDE {}
|
| -
|
| - virtual base::DictionaryValue* HandleCommand(
|
| - DevToolsAgentHost* agent_host,
|
| - base::DictionaryValue* command) OVERRIDE { return NULL; }
|
| -
|
| - virtual scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) OVERRIDE {
|
| - return scoped_ptr<DevToolsTarget>();
|
| - }
|
| -
|
| - virtual void EnumerateTargets(TargetCallback callback) OVERRIDE {
|
| - TargetList result;
|
| - DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
|
| - for (DevToolsAgentHost::List::iterator it = agents.begin();
|
| - it != agents.end(); ++it) {
|
| - if ((*it)->GetType() == DevToolsAgentHost::TYPE_WEB_CONTENTS)
|
| - result.insert(result.begin(), new TestTarget(*it));
|
| - else
|
| - result.push_back(new TestTarget(*it));
|
| - }
|
| - callback.Run(result);
|
| - }
|
| -
|
| - virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE {
|
| - return std::string();
|
| - }
|
| -};
|
| -
|
| -class ContentBrowserClientWithDevTools : public TestContentBrowserClient {
|
| - public:
|
| - explicit ContentBrowserClientWithDevTools(DevToolsManagerDelegate* delegate)
|
| - : delegate_(delegate) {}
|
| - virtual ~ContentBrowserClientWithDevTools() {}
|
| -
|
| - virtual content::DevToolsManagerDelegate*
|
| - GetDevToolsManagerDelegate() OVERRIDE {
|
| - return delegate_;
|
| - }
|
| - private:
|
| - DevToolsManagerDelegate* delegate_;
|
| -};
|
| -
|
| -class TestDevToolsManagerObserver : public DevToolsManager::Observer {
|
| - public:
|
| - TestDevToolsManagerObserver()
|
| - : updates_count_(0) {}
|
| - virtual ~TestDevToolsManagerObserver() {}
|
| -
|
| - int updates_count() { return updates_count_; }
|
| - const TargetList& target_list() { return target_list_; }
|
| -
|
| - virtual void TargetListChanged(const TargetList& targets) OVERRIDE {
|
| - updates_count_++;
|
| - target_list_ = targets;
|
| - base::MessageLoop::current()->PostTask(
|
| - FROM_HERE,
|
| - base::MessageLoop::QuitClosure());
|
| - }
|
| -
|
| - private:
|
| - int updates_count_;
|
| - TargetList target_list_;
|
| -};
|
| -
|
| } // namespace
|
|
|
| class DevToolsManagerTest : public RenderViewHostImplTestHarness {
|
| - public:
|
| - DevToolsManagerTest()
|
| - : delegate_(new TestDevToolsManagerDelegate()) {}
|
| -
|
| protected:
|
| virtual void SetUp() OVERRIDE {
|
| RenderViewHostImplTestHarness::SetUp();
|
| TestDevToolsClientHost::ResetCounters();
|
| - SetBrowserClientForTesting(new ContentBrowserClientWithDevTools(delegate_));
|
| - }
|
| -
|
| - TestDevToolsManagerDelegate* delegate_;
|
| + }
|
| };
|
|
|
| TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) {
|
| @@ -353,96 +239,4 @@
|
| client_host.Close();
|
| }
|
|
|
| -TEST_F(DevToolsManagerTest, TestObserver) {
|
| - GURL url1("data:text/html,<body>Body1</body>");
|
| - GURL url2("data:text/html,<body>Body2</body>");
|
| - GURL url3("data:text/html,<body>Body3</body>");
|
| -
|
| - DevToolsManager* manager = DevToolsManager::GetInstance();
|
| - DevToolsManager::SetObserverThrottleIntervalForTest(
|
| - base::TimeDelta::FromMilliseconds(200));
|
| -
|
| - contents()->NavigateAndCommit(url1);
|
| - RunAllPendingInMessageLoop();
|
| -
|
| - TestDevToolsManagerObserver* observer = new TestDevToolsManagerObserver();
|
| - manager->AddObserver(observer);
|
| - RunMessageLoop();
|
| - // Added observer should get an update.
|
| - EXPECT_EQ(1, observer->updates_count());
|
| - EXPECT_EQ(1u, observer->target_list().size());
|
| - EXPECT_EQ(contents(),
|
| - observer->target_list()[0]->GetAgentHost()->GetWebContents());
|
| - EXPECT_EQ(url1.spec(),
|
| - observer->target_list()[0]->GetURL().spec());
|
| -
|
| - contents()->NavigateAndCommit(url2);
|
| - RunAllPendingInMessageLoop();
|
| - contents()->NavigateAndCommit(url3);
|
| - RunMessageLoop();
|
| - // Updates should be coalesced.
|
| - EXPECT_EQ(2, observer->updates_count());
|
| - EXPECT_EQ(1u, observer->target_list().size());
|
| - EXPECT_EQ(contents(),
|
| - observer->target_list()[0]->GetAgentHost()->GetWebContents());
|
| - EXPECT_EQ(url3.spec(),
|
| - observer->target_list()[0]->GetURL().spec());
|
| -
|
| - base::MessageLoop::current()->PostDelayedTask(
|
| - FROM_HERE,
|
| - base::MessageLoop::QuitClosure(),
|
| - base::TimeDelta::FromMilliseconds(250));
|
| - base::MessageLoop::current()->Run();
|
| - // Check there were no extra updates.
|
| - EXPECT_EQ(2, observer->updates_count());
|
| -
|
| - scoped_ptr<WorkerStoragePartition> partition(new WorkerStoragePartition(
|
| - browser_context()->GetRequestContext(),
|
| - NULL, NULL, NULL, NULL, NULL, NULL, NULL));
|
| - WorkerStoragePartitionId partition_id(*partition.get());
|
| -
|
| - GURL shared_worker_url("http://example.com/shared_worker.js");
|
| - SharedWorkerInstance shared_worker(
|
| - shared_worker_url,
|
| - base::string16(),
|
| - base::string16(),
|
| - blink::WebContentSecurityPolicyTypeReport,
|
| - browser_context()->GetResourceContext(),
|
| - partition_id);
|
| - EmbeddedWorkerDevToolsManager::GetInstance()->SharedWorkerCreated(
|
| - 1, 1, shared_worker);
|
| - contents()->NavigateAndCommit(url2);
|
| -
|
| - RunMessageLoop();
|
| - EXPECT_EQ(3, observer->updates_count());
|
| - EXPECT_EQ(2u, observer->target_list().size());
|
| - EXPECT_EQ(contents(),
|
| - observer->target_list()[0]->GetAgentHost()->GetWebContents());
|
| - EXPECT_EQ(url2.spec(),
|
| - observer->target_list()[0]->GetURL().spec());
|
| - EXPECT_EQ(DevToolsAgentHost::TYPE_SHARED_WORKER,
|
| - observer->target_list()[1]->GetAgentHost()->GetType());
|
| - EXPECT_EQ(shared_worker_url.spec(),
|
| - observer->target_list()[1]->GetURL().spec());
|
| -
|
| - EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed(1, 1);
|
| - RunMessageLoop();
|
| - EXPECT_EQ(4, observer->updates_count());
|
| - EXPECT_EQ(1u, observer->target_list().size());
|
| - EXPECT_EQ(contents(),
|
| - observer->target_list()[0]->GetAgentHost()->GetWebContents());
|
| - EXPECT_EQ(url2.spec(),
|
| - observer->target_list()[0]->GetURL().spec());
|
| -
|
| - base::MessageLoop::current()->PostDelayedTask(
|
| - FROM_HERE,
|
| - base::MessageLoop::QuitClosure(),
|
| - base::TimeDelta::FromMilliseconds(250));
|
| - base::MessageLoop::current()->Run();
|
| - // Check there were no extra updates.
|
| - EXPECT_EQ(4, observer->updates_count());
|
| -
|
| - manager->RemoveObserver(observer);
|
| -}
|
| -
|
| } // namespace content
|
|
|