OLD | NEW |
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 DevToolsAgentHostClient { |
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_->DispatchProtocolMessage( |
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(shell()->web_contents()); |
62 DevToolsAgentHost::GetOrCreateFor(shell()->web_contents()).get(), this); | 61 agent_host_->AttachClient(this); |
63 } | 62 } |
64 | 63 |
65 virtual void TearDownOnMainThread() OVERRIDE { | 64 virtual void TearDownOnMainThread() OVERRIDE { |
66 DevToolsManager::GetInstance()->ClientHostClosing(this); | 65 agent_host_->DetachClient(); |
| 66 agent_host_ = NULL; |
67 } | 67 } |
68 | 68 |
69 virtual void DispatchOnInspectorFrontend( | 69 virtual void DispatchProtocolMessage( |
70 const std::string& message) OVERRIDE { | 70 DevToolsAgentHost* agent_host, 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 InspectedContentsClosing() OVERRIDE { | 79 virtual void AgentHostClosed( |
80 EXPECT_TRUE(false); | 80 DevToolsAgentHost* agent_host, bool replaced) OVERRIDE { |
81 } | |
82 | |
83 virtual void ReplacedWithAnotherClient() OVERRIDE { | |
84 EXPECT_TRUE(false); | 81 EXPECT_TRUE(false); |
85 } | 82 } |
86 }; | 83 }; |
87 | 84 |
88 IN_PROC_BROWSER_TEST_F(RendererOverridesHandlerTest, QueryUsageAndQuota) { | 85 IN_PROC_BROWSER_TEST_F(RendererOverridesHandlerTest, QueryUsageAndQuota) { |
89 base::DictionaryValue* params = new base::DictionaryValue(); | 86 base::DictionaryValue* params = new base::DictionaryValue(); |
90 params->SetString("securityOrigin", "http://example.com"); | 87 params->SetString("securityOrigin", "http://example.com"); |
91 SendCommand("Page.queryUsageAndQuota", params); | 88 SendCommand("Page.queryUsageAndQuota", params); |
92 | 89 |
93 EXPECT_TRUE(HasValue("quota.persistent")); | 90 EXPECT_TRUE(HasValue("quota.persistent")); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 SkBitmap bitmap; | 124 SkBitmap bitmap; |
128 gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(png.data()), | 125 gfx::PNGCodec::Decode(reinterpret_cast<const unsigned char*>(png.data()), |
129 png.size(), &bitmap); | 126 png.size(), &bitmap); |
130 SkColor color(bitmap.getColor(0, 0)); | 127 SkColor color(bitmap.getColor(0, 0)); |
131 EXPECT_TRUE(std::abs(0x12-(int)SkColorGetR(color)) <= 1); | 128 EXPECT_TRUE(std::abs(0x12-(int)SkColorGetR(color)) <= 1); |
132 EXPECT_TRUE(std::abs(0x34-(int)SkColorGetG(color)) <= 1); | 129 EXPECT_TRUE(std::abs(0x34-(int)SkColorGetG(color)) <= 1); |
133 EXPECT_TRUE(std::abs(0x56-(int)SkColorGetB(color)) <= 1); | 130 EXPECT_TRUE(std::abs(0x56-(int)SkColorGetB(color)) <= 1); |
134 } | 131 } |
135 | 132 |
136 } // namespace content | 133 } // namespace content |
OLD | NEW |