OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "base/json/json_string_value_serializer.h" |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "content/browser/devtools/renderer_overrides_handler.h" |
| 9 #include "content/public/browser/devtools_agent_host.h" |
| 10 #include "content/public/browser/web_contents.h" |
| 11 #include "content/shell/browser/shell.h" |
| 12 #include "content/test/content_browser_test.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 class RendererOverridesHandlerTest : public ContentBrowserTest { |
| 17 public: |
| 18 scoped_ptr<base::DictionaryValue> last_message_; |
| 19 |
| 20 void OnMessageSent(const std::string& message) { |
| 21 JSONStringValueSerializer serializer(message); |
| 22 int error_code; |
| 23 std::string error_message; |
| 24 base::Value* root = |
| 25 serializer.Deserialize(&error_code, &error_message); |
| 26 base::DictionaryValue* root_dictionary; |
| 27 root->GetAsDictionary(&root_dictionary); |
| 28 base::DictionaryValue* result; |
| 29 root_dictionary->GetDictionary("result", &result); |
| 30 last_message_.reset(result); |
| 31 base::MessageLoop::current()->QuitNow(); |
| 32 } |
| 33 |
| 34 bool HasValue(const std::string& path) { |
| 35 base::Value* value = 0; |
| 36 return last_message_->Get(path, &value); |
| 37 } |
| 38 |
| 39 bool HasUsageItem(const std::string& path_to_list, |
| 40 const std::string& usage_item_id) { |
| 41 base::ListValue* list; |
| 42 if (!last_message_->GetList(path_to_list, &list)) |
| 43 return false; |
| 44 |
| 45 for (size_t i = 0; i != list->GetSize(); i++) { |
| 46 base::DictionaryValue* item; |
| 47 if (!list->GetDictionary(i, &item)) |
| 48 return false; |
| 49 std::string id; |
| 50 if (!item->GetString("id", &id)) |
| 51 return false; |
| 52 if (id == usage_item_id) |
| 53 return true; |
| 54 } |
| 55 return false; |
| 56 } |
| 57 }; |
| 58 |
| 59 IN_PROC_BROWSER_TEST_F(RendererOverridesHandlerTest, QueryUsageAndQuota) { |
| 60 |
| 61 RenderViewHost* rvh = shell()->web_contents()->GetRenderViewHost(); |
| 62 DevToolsAgentHost* agent_raw = DevToolsAgentHost::GetOrCreateFor(rvh).get(); |
| 63 scoped_ptr<RendererOverridesHandler> handler( |
| 64 new RendererOverridesHandler(agent_raw)); |
| 65 |
| 66 handler->SetNotifier(base::Bind( |
| 67 &RendererOverridesHandlerTest::OnMessageSent, base::Unretained(this))); |
| 68 |
| 69 std::string error_response; |
| 70 scoped_refptr<DevToolsProtocol::Command> command = |
| 71 DevToolsProtocol::ParseCommand("{" |
| 72 "\"id\": 1," |
| 73 "\"method\": \"Page.queryUsageAndQuota\"," |
| 74 "\"params\": {" |
| 75 "\"securityOrigin\": \"http://example.com\"" |
| 76 "}" |
| 77 "}", &error_response); |
| 78 ASSERT_TRUE(command.get()); |
| 79 |
| 80 scoped_refptr<DevToolsProtocol::Response> response = |
| 81 handler->HandleCommand(command); |
| 82 |
| 83 base::MessageLoop::current()->Run(); |
| 84 |
| 85 EXPECT_TRUE(HasValue("quota.persistent")); |
| 86 EXPECT_TRUE(HasValue("quota.temporary")); |
| 87 EXPECT_TRUE(HasUsageItem("usage.temporary", "appcache")); |
| 88 EXPECT_TRUE(HasUsageItem("usage.temporary", "database")); |
| 89 EXPECT_TRUE(HasUsageItem("usage.temporary", "indexeddatabase")); |
| 90 EXPECT_TRUE(HasUsageItem("usage.temporary", "filesystem")); |
| 91 EXPECT_TRUE(HasUsageItem("usage.persistent", "filesystem")); |
| 92 } |
| 93 |
| 94 } // namespace content |
| 95 |
OLD | NEW |