OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 #import "chrome/browser/ui/cocoa/applescript/apple_event_util.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/json/json_reader.h" |
| 9 #include "base/stringprintf.h" |
| 10 #include "base/values.h" |
| 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 12 #include "testing/gtest_mac.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 class AppleEventUtilTest : public CocoaTest { }; |
| 17 |
| 18 struct TestCase { |
| 19 const char* json_input; |
| 20 const char* expected_aedesc_dump; |
| 21 DescType expected_aedesc_type; |
| 22 }; |
| 23 |
| 24 TEST_F(AppleEventUtilTest, ValueToAppleEventDescriptor) { |
| 25 const struct TestCase cases[] = { |
| 26 { "null", "'msng'", typeType }, |
| 27 { "true", "-255", typeBoolean }, |
| 28 { "false", "-256", typeBoolean }, |
| 29 { "-1000", "-1000", typeSInt32 }, |
| 30 { "0", "0", typeSInt32 }, |
| 31 { "1000", "1000", typeSInt32 }, |
| 32 { "-1e100", "-1e+100", typeIEEE64BitFloatingPoint }, |
| 33 { "0.0", "0", typeIEEE64BitFloatingPoint }, |
| 34 { "1e100", "1e+100", typeIEEE64BitFloatingPoint }, |
| 35 { "\"\"", "'utxt'(\"\")", typeUnicodeText }, |
| 36 { "\"string\"", "'utxt'(\"string\")", typeUnicodeText }, |
| 37 { "{}", "{ 'usrf':[ ] }", typeAERecord }, |
| 38 { "[]", "[ ]", typeAEList }, |
| 39 { "{\"Image\": {" |
| 40 "\"Width\": 800," |
| 41 "\"Height\": 600," |
| 42 "\"Title\": \"View from 15th Floor\"," |
| 43 "\"Thumbnail\": {" |
| 44 "\"Url\": \"http://www.example.com/image/481989943\"," |
| 45 "\"Height\": 125," |
| 46 "\"Width\": \"100\"" |
| 47 "}," |
| 48 "\"IDs\": [116, 943, 234, 38793]" |
| 49 "}" |
| 50 "}", |
| 51 "{ 'usrf':[ 'utxt'(\"Image\"), { 'usrf':[ 'utxt'(\"Height\"), 600, " |
| 52 "'utxt'(\"IDs\"), [ 116, 943, 234, 38793 ], 'utxt'(\"Thumbnail\"), " |
| 53 "{ 'usrf':[ 'utxt'(\"Height\"), 125, 'utxt'(\"Url\"), " |
| 54 "'utxt'(\"http://www.example.com/image/481989943\"), 'utxt'(\"Width\"), " |
| 55 "'utxt'(\"100\") ] }, 'utxt'(\"Title\"), " |
| 56 "'utxt'(\"View from 15th Floor\"), 'utxt'(\"Width\"), 800 ] } ] }", |
| 57 typeAERecord }, |
| 58 { "[" |
| 59 "{" |
| 60 "\"precision\": \"zip\"," |
| 61 "\"Latitude\": 37.7668," |
| 62 "\"Longitude\": -122.3959," |
| 63 "\"Address\": \"\"," |
| 64 "\"City\": \"SAN FRANCISCO\"," |
| 65 "\"State\": \"CA\"," |
| 66 "\"Zip\": \"94107\"," |
| 67 "\"Country\": \"US\"" |
| 68 "}," |
| 69 "{" |
| 70 "\"precision\": \"zip\"," |
| 71 "\"Latitude\": 37.371991," |
| 72 "\"Longitude\": -122.026020," |
| 73 "\"Address\": \"\"," |
| 74 "\"City\": \"SUNNYVALE\"," |
| 75 "\"State\": \"CA\"," |
| 76 "\"Zip\": \"94085\"," |
| 77 "\"Country\": \"US\"" |
| 78 "}" |
| 79 "]", |
| 80 "[ { 'usrf':[ 'utxt'(\"Address\"), 'utxt'(\"\"), 'utxt'(\"City\"), " |
| 81 "'utxt'(\"SAN FRANCISCO\"), 'utxt'(\"Country\"), 'utxt'(\"US\"), " |
| 82 "'utxt'(\"Latitude\"), 37.7668, 'utxt'(\"Longitude\"), -122.396, " |
| 83 "'utxt'(\"State\"), 'utxt'(\"CA\"), 'utxt'(\"Zip\"), 'utxt'(\"94107\"), " |
| 84 "'utxt'(\"precision\"), 'utxt'(\"zip\") ] }, { 'usrf':[ " |
| 85 "'utxt'(\"Address\"), 'utxt'(\"\"), 'utxt'(\"City\"), " |
| 86 "'utxt'(\"SUNNYVALE\"), 'utxt'(\"Country\"), 'utxt'(\"US\"), " |
| 87 "'utxt'(\"Latitude\"), 37.372, 'utxt'(\"Longitude\"), -122.026, " |
| 88 "'utxt'(\"State\"), 'utxt'(\"CA\"), 'utxt'(\"Zip\"), 'utxt'(\"94085\"), " |
| 89 "'utxt'(\"precision\"), 'utxt'(\"zip\") ] } ]", |
| 90 typeAEList }, |
| 91 }; |
| 92 |
| 93 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 94 scoped_ptr<base::Value> value(base::JSONReader::Read(cases[i].json_input)); |
| 95 NSAppleEventDescriptor* descriptor = |
| 96 ValueToAppleEventDescriptor(value.get()); |
| 97 NSString* descriptor_description = [descriptor description]; |
| 98 |
| 99 std::string expected_contents = |
| 100 base::StringPrintf("<NSAppleEventDescriptor: %s>", |
| 101 cases[i].expected_aedesc_dump); |
| 102 EXPECT_STREQ(expected_contents.c_str(), |
| 103 [descriptor_description UTF8String]) << "i: " << i; |
| 104 EXPECT_EQ(cases[i].expected_aedesc_type, |
| 105 [descriptor descriptorType]) << "i: " << i; |
| 106 } |
| 107 } |
| 108 |
| 109 } // namespace |
OLD | NEW |