| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/nacl/nacl_browsertest_util.h" | 5 #include "chrome/test/nacl/nacl_browsertest_util.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "components/nacl/common/nacl_switches.h" | 17 #include "components/nacl/common/nacl_switches.h" |
| 18 #include "content/public/browser/plugin_service.h" | 18 #include "content/public/browser/plugin_service.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/webplugininfo.h" | 20 #include "content/public/common/webplugininfo.h" |
| 21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 22 | 22 |
| 23 typedef content::TestMessageHandler::MessageResponse MessageResponse; | 23 typedef content::TestMessageHandler::MessageResponse MessageResponse; |
| 24 | 24 |
| 25 MessageResponse StructuredMessageHandler::HandleMessage( | 25 MessageResponse StructuredMessageHandler::HandleMessage( |
| 26 const std::string& json) { | 26 const std::string& json) { |
| 27 scoped_ptr<base::Value> value; | |
| 28 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); | 27 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); |
| 29 // Automation messages are stringified before they are sent because the | 28 // Automation messages are stringified before they are sent because the |
| 30 // automation channel cannot handle arbitrary objects. This means we | 29 // automation channel cannot handle arbitrary objects. This means we |
| 31 // need to decode the json twice to get the original message. | 30 // need to decode the json twice to get the original message. |
| 32 value.reset(reader.ReadToValue(json)); | 31 scoped_ptr<base::Value> value = reader.ReadToValue(json); |
| 33 if (!value.get()) | 32 if (!value.get()) |
| 34 return InternalError("Could parse automation JSON: " + json + | 33 return InternalError("Could parse automation JSON: " + json + |
| 35 " because " + reader.GetErrorMessage()); | 34 " because " + reader.GetErrorMessage()); |
| 36 | 35 |
| 37 std::string temp; | 36 std::string temp; |
| 38 if (!value->GetAsString(&temp)) | 37 if (!value->GetAsString(&temp)) |
| 39 return InternalError("Message was not a string: " + json); | 38 return InternalError("Message was not a string: " + json); |
| 40 | 39 |
| 41 value.reset(reader.ReadToValue(temp)); | 40 value = reader.ReadToValue(temp); |
| 42 if (!value.get()) | 41 if (!value.get()) |
| 43 return InternalError("Could not parse message JSON: " + temp + | 42 return InternalError("Could not parse message JSON: " + temp + |
| 44 " because " + reader.GetErrorMessage()); | 43 " because " + reader.GetErrorMessage()); |
| 45 | 44 |
| 46 base::DictionaryValue* msg; | 45 base::DictionaryValue* msg; |
| 47 if (!value->GetAsDictionary(&msg)) | 46 if (!value->GetAsDictionary(&msg)) |
| 48 return InternalError("Message was not an object: " + temp); | 47 return InternalError("Message was not an object: " + temp); |
| 49 | 48 |
| 50 std::string type; | 49 std::string type; |
| 51 if (!msg->GetString("type", &type)) | 50 if (!msg->GetString("type", &type)) |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // to point at the isolated the test extension directory. | 357 // to point at the isolated the test extension directory. |
| 359 // Otherwise, multiple NaCl extensions tests will end up sharing the | 358 // Otherwise, multiple NaCl extensions tests will end up sharing the |
| 360 // same directory when loading the extension files. | 359 // same directory when loading the extension files. |
| 361 base::FilePath document_root; | 360 base::FilePath document_root; |
| 362 ASSERT_TRUE(GetDocumentRoot(&document_root)); | 361 ASSERT_TRUE(GetDocumentRoot(&document_root)); |
| 363 | 362 |
| 364 // Document root is relative to source root, and source root may not be CWD. | 363 // Document root is relative to source root, and source root may not be CWD. |
| 365 command_line->AppendSwitchPath(switches::kLoadExtension, | 364 command_line->AppendSwitchPath(switches::kLoadExtension, |
| 366 src_root.Append(document_root)); | 365 src_root.Append(document_root)); |
| 367 } | 366 } |
| OLD | NEW |