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

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

Issue 467653002: Revert of [DevTools] Make DevTools clients talk directly to DevToolsAgentHost instead of using DevToolsManage… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
10 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
11 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/content_browser_test.h" 14 #include "content/public/test/content_browser_test.h"
13 #include "content/shell/browser/shell.h" 15 #include "content/shell/browser/shell.h"
14 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/compositor/compositor_switches.h" 17 #include "ui/compositor/compositor_switches.h"
16 #include "ui/gfx/codec/png_codec.h" 18 #include "ui/gfx/codec/png_codec.h"
17 19
18 namespace content { 20 namespace content {
19 21
20 class RendererOverridesHandlerTest : public ContentBrowserTest, 22 class RendererOverridesHandlerTest : public ContentBrowserTest,
21 public DevToolsAgentHostClient { 23 public DevToolsClientHost {
22 protected: 24 protected:
23 void SendCommand(const std::string& method, 25 void SendCommand(const std::string& method,
24 base::DictionaryValue* params) { 26 base::DictionaryValue* params) {
25 agent_host_->DispatchProtocolMessage( 27 EXPECT_TRUE(DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this,
26 DevToolsProtocol::CreateCommand(1, method, params)->Serialize()); 28 DevToolsProtocol::CreateCommand(1, method, params)->Serialize()));
27 base::MessageLoop::current()->Run(); 29 base::MessageLoop::current()->Run();
28 } 30 }
29 31
30 bool HasValue(const std::string& path) { 32 bool HasValue(const std::string& path) {
31 base::Value* value = 0; 33 base::Value* value = 0;
32 return result_->Get(path, &value); 34 return result_->Get(path, &value);
33 } 35 }
34 36
35 bool HasListItem(const std::string& path_to_list, 37 bool HasListItem(const std::string& path_to_list,
36 const std::string& name, 38 const std::string& name,
37 const std::string& value) { 39 const std::string& value) {
38 base::ListValue* list; 40 base::ListValue* list;
39 if (!result_->GetList(path_to_list, &list)) 41 if (!result_->GetList(path_to_list, &list))
40 return false; 42 return false;
41 43
42 for (size_t i = 0; i != list->GetSize(); i++) { 44 for (size_t i = 0; i != list->GetSize(); i++) {
43 base::DictionaryValue* item; 45 base::DictionaryValue* item;
44 if (!list->GetDictionary(i, &item)) 46 if (!list->GetDictionary(i, &item))
45 return false; 47 return false;
46 std::string id; 48 std::string id;
47 if (!item->GetString(name, &id)) 49 if (!item->GetString(name, &id))
48 return false; 50 return false;
49 if (id == value) 51 if (id == value)
50 return true; 52 return true;
51 } 53 }
52 return false; 54 return false;
53 } 55 }
54 56
55 scoped_ptr<base::DictionaryValue> result_; 57 scoped_ptr<base::DictionaryValue> result_;
56 scoped_refptr<DevToolsAgentHost> agent_host_;
57 58
58 private: 59 private:
59 virtual void SetUpOnMainThread() OVERRIDE { 60 virtual void SetUpOnMainThread() OVERRIDE {
60 agent_host_ = DevToolsAgentHost::GetOrCreateFor(shell()->web_contents()); 61 DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
61 agent_host_->AttachClient(this); 62 DevToolsAgentHost::GetOrCreateFor(shell()->web_contents()).get(), this);
62 } 63 }
63 64
64 virtual void TearDownOnMainThread() OVERRIDE { 65 virtual void TearDownOnMainThread() OVERRIDE {
65 agent_host_->DetachClient(); 66 DevToolsManager::GetInstance()->ClientHostClosing(this);
66 agent_host_ = NULL;
67 } 67 }
68 68
69 virtual void DispatchProtocolMessage( 69 virtual void DispatchOnInspectorFrontend(
70 DevToolsAgentHost* agent_host, const std::string& message) OVERRIDE { 70 const std::string& message) OVERRIDE {
71 scoped_ptr<base::DictionaryValue> root( 71 scoped_ptr<base::DictionaryValue> root(
72 static_cast<base::DictionaryValue*>(base::JSONReader::Read(message))); 72 static_cast<base::DictionaryValue*>(base::JSONReader::Read(message)));
73 base::DictionaryValue* result; 73 base::DictionaryValue* result;
74 EXPECT_TRUE(root->GetDictionary("result", &result)); 74 EXPECT_TRUE(root->GetDictionary("result", &result));
75 result_.reset(result->DeepCopy()); 75 result_.reset(result->DeepCopy());
76 base::MessageLoop::current()->QuitNow(); 76 base::MessageLoop::current()->QuitNow();
77 } 77 }
78 78
79 virtual void AgentHostClosed( 79 virtual void InspectedContentsClosing() OVERRIDE {
80 DevToolsAgentHost* agent_host, bool replaced) OVERRIDE { 80 EXPECT_TRUE(false);
81 }
82
83 virtual void ReplacedWithAnotherClient() OVERRIDE {
81 EXPECT_TRUE(false); 84 EXPECT_TRUE(false);
82 } 85 }
83 }; 86 };
84 87
85 IN_PROC_BROWSER_TEST_F(RendererOverridesHandlerTest, QueryUsageAndQuota) { 88 IN_PROC_BROWSER_TEST_F(RendererOverridesHandlerTest, QueryUsageAndQuota) {
86 base::DictionaryValue* params = new base::DictionaryValue(); 89 base::DictionaryValue* params = new base::DictionaryValue();
87 params->SetString("securityOrigin", "http://example.com"); 90 params->SetString("securityOrigin", "http://example.com");
88 SendCommand("Page.queryUsageAndQuota", params); 91 SendCommand("Page.queryUsageAndQuota", params);
89 92
90 EXPECT_TRUE(HasValue("quota.persistent")); 93 EXPECT_TRUE(HasValue("quota.persistent"));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 SkBitmap bitmap; 127 SkBitmap bitmap;
125 gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(png.data()), 128 gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(png.data()),
126 png.size(), &bitmap); 129 png.size(), &bitmap);
127 SkColor color(bitmap.getColor(0, 0)); 130 SkColor color(bitmap.getColor(0, 0));
128 EXPECT_TRUE(std::abs(0x12-(int)SkColorGetR(color)) <= 1); 131 EXPECT_TRUE(std::abs(0x12-(int)SkColorGetR(color)) <= 1);
129 EXPECT_TRUE(std::abs(0x34-(int)SkColorGetG(color)) <= 1); 132 EXPECT_TRUE(std::abs(0x34-(int)SkColorGetG(color)) <= 1);
130 EXPECT_TRUE(std::abs(0x56-(int)SkColorGetB(color)) <= 1); 133 EXPECT_TRUE(std::abs(0x56-(int)SkColorGetB(color)) <= 1);
131 } 134 }
132 135
133 } // namespace content 136 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/render_view_devtools_agent_host.cc ('k') | content/browser/devtools/tethering_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698