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/macros.h" | 10 #include "base/macros.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "components/nacl/common/nacl_switches.h" | 18 #include "components/nacl/common/nacl_switches.h" |
19 #include "content/public/browser/plugin_service.h" | 19 #include "content/public/browser/plugin_service.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/webplugininfo.h" | 21 #include "content/public/common/webplugininfo.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 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); | 27 base::JSONReader reader(base::JSON_ALLOW_TRAILING_COMMAS); |
28 // Automation messages are stringified before they are sent because the | |
29 // automation channel cannot handle arbitrary objects. This means we | |
30 // need to decode the json twice to get the original message. | |
31 std::unique_ptr<base::Value> value = reader.ReadToValue(json); | 28 std::unique_ptr<base::Value> value = reader.ReadToValue(json); |
32 if (!value.get()) | 29 if (!value.get()) |
33 return InternalError("Could parse automation JSON: " + json + | 30 return InternalError("Could parse automation JSON: " + json + |
34 " because " + reader.GetErrorMessage()); | 31 " because " + reader.GetErrorMessage()); |
35 | 32 |
36 std::string temp; | |
37 if (!value->GetAsString(&temp)) | |
38 return InternalError("Message was not a string: " + json); | |
39 | |
40 value = reader.ReadToValue(temp); | |
41 if (!value.get()) | |
42 return InternalError("Could not parse message JSON: " + temp + | |
43 " because " + reader.GetErrorMessage()); | |
44 | |
45 base::DictionaryValue* msg; | 33 base::DictionaryValue* msg; |
46 if (!value->GetAsDictionary(&msg)) | 34 if (!value->GetAsDictionary(&msg)) |
47 return InternalError("Message was not an object: " + temp); | 35 return InternalError("Message was not an object: " + json); |
48 | 36 |
49 std::string type; | 37 std::string type; |
50 if (!msg->GetString("type", &type)) | 38 if (!msg->GetString("type", &type)) |
51 return MissingField("unknown", "type"); | 39 return MissingField("unknown", "type"); |
52 | 40 |
53 return HandleStructuredMessage(type, msg); | 41 return HandleStructuredMessage(type, msg); |
54 } | 42 } |
55 | 43 |
56 MessageResponse StructuredMessageHandler::MissingField( | 44 MessageResponse StructuredMessageHandler::MissingField( |
57 const std::string& type, | 45 const std::string& type, |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // to point at the isolated the test extension directory. | 331 // to point at the isolated the test extension directory. |
344 // Otherwise, multiple NaCl extensions tests will end up sharing the | 332 // Otherwise, multiple NaCl extensions tests will end up sharing the |
345 // same directory when loading the extension files. | 333 // same directory when loading the extension files. |
346 base::FilePath document_root; | 334 base::FilePath document_root; |
347 ASSERT_TRUE(GetDocumentRoot(&document_root)); | 335 ASSERT_TRUE(GetDocumentRoot(&document_root)); |
348 | 336 |
349 // Document root is relative to source root, and source root may not be CWD. | 337 // Document root is relative to source root, and source root may not be CWD. |
350 command_line->AppendSwitchPath(switches::kLoadExtension, | 338 command_line->AppendSwitchPath(switches::kLoadExtension, |
351 src_root.Append(document_root)); | 339 src_root.Append(document_root)); |
352 } | 340 } |
OLD | NEW |