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

Side by Side Diff: content/browser/devtools/renderer_overrides_handler_browsertest.cc

Issue 449043002: [DevTools] Make DevTools clients talk directly to DevToolsAgentHost instead of using DevToolsManage… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/base64.h" 5 #include "base/base64.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "content/browser/devtools/devtools_protocol.h" 8 #include "content/browser/devtools/devtools_protocol.h"
9 #include "content/public/browser/devtools_agent_host.h" 9 #include "content/public/browser/devtools_agent_host.h"
10 #include "content/public/browser/devtools_client_host.h"
11 #include "content/public/browser/devtools_manager.h"
12 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/browser_test_utils.h" 11 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/content_browser_test.h" 12 #include "content/public/test/content_browser_test.h"
15 #include "content/shell/browser/shell.h" 13 #include "content/shell/browser/shell.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "ui/compositor/compositor_switches.h" 15 #include "ui/compositor/compositor_switches.h"
18 #include "ui/gfx/codec/png_codec.h" 16 #include "ui/gfx/codec/png_codec.h"
19 17
20 namespace content { 18 namespace content {
21 19
22 class RendererOverridesHandlerTest : public ContentBrowserTest, 20 class RendererOverridesHandlerTest : public ContentBrowserTest,
23 public DevToolsClientHost { 21 public DevToolsAgentHost::Client {
24 protected: 22 protected:
25 void SendCommand(const std::string& method, 23 void SendCommand(const std::string& method,
26 base::DictionaryValue* params) { 24 base::DictionaryValue* params) {
27 EXPECT_TRUE(DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, 25 agent_host_->DispatchOnInspectorBackend(
28 DevToolsProtocol::CreateCommand(1, method, params)->Serialize())); 26 DevToolsProtocol::CreateCommand(1, method, params)->Serialize());
29 base::MessageLoop::current()->Run(); 27 base::MessageLoop::current()->Run();
30 } 28 }
31 29
32 bool HasValue(const std::string& path) { 30 bool HasValue(const std::string& path) {
33 base::Value* value = 0; 31 base::Value* value = 0;
34 return result_->Get(path, &value); 32 return result_->Get(path, &value);
35 } 33 }
36 34
37 bool HasListItem(const std::string& path_to_list, 35 bool HasListItem(const std::string& path_to_list,
38 const std::string& name, 36 const std::string& name,
39 const std::string& value) { 37 const std::string& value) {
40 base::ListValue* list; 38 base::ListValue* list;
41 if (!result_->GetList(path_to_list, &list)) 39 if (!result_->GetList(path_to_list, &list))
42 return false; 40 return false;
43 41
44 for (size_t i = 0; i != list->GetSize(); i++) { 42 for (size_t i = 0; i != list->GetSize(); i++) {
45 base::DictionaryValue* item; 43 base::DictionaryValue* item;
46 if (!list->GetDictionary(i, &item)) 44 if (!list->GetDictionary(i, &item))
47 return false; 45 return false;
48 std::string id; 46 std::string id;
49 if (!item->GetString(name, &id)) 47 if (!item->GetString(name, &id))
50 return false; 48 return false;
51 if (id == value) 49 if (id == value)
52 return true; 50 return true;
53 } 51 }
54 return false; 52 return false;
55 } 53 }
56 54
57 scoped_ptr<base::DictionaryValue> result_; 55 scoped_ptr<base::DictionaryValue> result_;
56 scoped_refptr<DevToolsAgentHost> agent_host_;
58 57
59 private: 58 private:
60 virtual void SetUpOnMainThread() OVERRIDE { 59 virtual void SetUpOnMainThread() OVERRIDE {
61 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( 60 agent_host_ = DevToolsAgentHost::GetOrCreateFor(
62 DevToolsAgentHost::GetOrCreateFor( 61 shell()->web_contents()->GetRenderViewHost());
63 shell()->web_contents()->GetRenderViewHost()).get(), 62 agent_host_->AttachClient(this);
64 this);
65 } 63 }
66 64
67 virtual void TearDownOnMainThread() OVERRIDE { 65 virtual void TearDownOnMainThread() OVERRIDE {
68 DevToolsManager::GetInstance()->ClientHostClosing(this); 66 agent_host_->DetachClient();
67 agent_host_ = NULL;
69 } 68 }
70 69
71 virtual void DispatchOnInspectorFrontend( 70 virtual void SendMessageFromAgentHost(
72 const std::string& message) OVERRIDE { 71 DevToolsAgentHost* agent_host, const std::string& message) OVERRIDE {
73 scoped_ptr<base::DictionaryValue> root( 72 scoped_ptr<base::DictionaryValue> root(
74 static_cast<base::DictionaryValue*>(base::JSONReader::Read(message))); 73 static_cast<base::DictionaryValue*>(base::JSONReader::Read(message)));
75 base::DictionaryValue* result; 74 base::DictionaryValue* result;
76 EXPECT_TRUE(root->GetDictionary("result", &result)); 75 EXPECT_TRUE(root->GetDictionary("result", &result));
77 result_.reset(result->DeepCopy()); 76 result_.reset(result->DeepCopy());
78 base::MessageLoop::current()->QuitNow(); 77 base::MessageLoop::current()->QuitNow();
79 } 78 }
80 79
81 virtual void InspectedContentsClosing() OVERRIDE { 80 virtual void AgentHostDetached(
82 EXPECT_TRUE(false); 81 DevToolsAgentHost* agent_host,
83 } 82 DevToolsAgentHost::DetachReason reason) OVERRIDE {
84 83 EXPECT_EQ(DevToolsAgentHost::DETACHED_BY_CLIENT, reason);
85 virtual void ReplacedWithAnotherClient() OVERRIDE {
86 EXPECT_TRUE(false);
87 } 84 }
88 }; 85 };
89 86
90 IN_PROC_BROWSER_TEST_F(RendererOverridesHandlerTest, QueryUsageAndQuota) { 87 IN_PROC_BROWSER_TEST_F(RendererOverridesHandlerTest, QueryUsageAndQuota) {
91 base::DictionaryValue* params = new base::DictionaryValue(); 88 base::DictionaryValue* params = new base::DictionaryValue();
92 params->SetString("securityOrigin", "http://example.com"); 89 params->SetString("securityOrigin", "http://example.com");
93 SendCommand("Page.queryUsageAndQuota", params); 90 SendCommand("Page.queryUsageAndQuota", params);
94 91
95 EXPECT_TRUE(HasValue("quota.persistent")); 92 EXPECT_TRUE(HasValue("quota.persistent"));
96 EXPECT_TRUE(HasValue("quota.temporary")); 93 EXPECT_TRUE(HasValue("quota.temporary"));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 SkBitmap bitmap; 126 SkBitmap bitmap;
130 gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(png.data()), 127 gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(png.data()),
131 png.size(), &bitmap); 128 png.size(), &bitmap);
132 SkColor color(bitmap.getColor(0, 0)); 129 SkColor color(bitmap.getColor(0, 0));
133 EXPECT_TRUE(std::abs(0x12-(int)SkColorGetR(color)) <= 1); 130 EXPECT_TRUE(std::abs(0x12-(int)SkColorGetR(color)) <= 1);
134 EXPECT_TRUE(std::abs(0x34-(int)SkColorGetG(color)) <= 1); 131 EXPECT_TRUE(std::abs(0x34-(int)SkColorGetG(color)) <= 1);
135 EXPECT_TRUE(std::abs(0x56-(int)SkColorGetB(color)) <= 1); 132 EXPECT_TRUE(std::abs(0x56-(int)SkColorGetB(color)) <= 1);
136 } 133 }
137 134
138 } // namespace content 135 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698