| Index: chrome/browser/ui/cocoa/applescript/apple_event_util_unittest.mm
|
| diff --git a/chrome/browser/ui/cocoa/applescript/apple_event_util_unittest.mm b/chrome/browser/ui/cocoa/applescript/apple_event_util_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ada182b8e57f64a1996be89694d337db1d4ed976
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/cocoa/applescript/apple_event_util_unittest.mm
|
| @@ -0,0 +1,109 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "chrome/browser/ui/cocoa/applescript/apple_event_util.h"
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/json/json_reader.h"
|
| +#include "base/stringprintf.h"
|
| +#include "base/values.h"
|
| +#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
|
| +#include "testing/gtest_mac.h"
|
| +
|
| +namespace {
|
| +
|
| +class AppleEventUtilTest : public CocoaTest { };
|
| +
|
| +struct TestCase {
|
| + const char* json_input;
|
| + const char* expected_aedesc_dump;
|
| + DescType expected_aedesc_type;
|
| +};
|
| +
|
| +TEST_F(AppleEventUtilTest, ValueToAppleEventDescriptor) {
|
| + const struct TestCase cases[] = {
|
| + { "null", "'msng'", typeType },
|
| + { "true", "-255", typeBoolean },
|
| + { "false", "-256", typeBoolean },
|
| + { "-1000", "-1000", typeSInt32 },
|
| + { "0", "0", typeSInt32 },
|
| + { "1000", "1000", typeSInt32 },
|
| + { "-1e100", "-1e+100", typeIEEE64BitFloatingPoint },
|
| + { "0.0", "0", typeIEEE64BitFloatingPoint },
|
| + { "1e100", "1e+100", typeIEEE64BitFloatingPoint },
|
| + { "\"\"", "'utxt'(\"\")", typeUnicodeText },
|
| + { "\"string\"", "'utxt'(\"string\")", typeUnicodeText },
|
| + { "{}", "{ 'usrf':[ ] }", typeAERecord },
|
| + { "[]", "[ ]", typeAEList },
|
| + { "{\"Image\": {"
|
| + "\"Width\": 800,"
|
| + "\"Height\": 600,"
|
| + "\"Title\": \"View from 15th Floor\","
|
| + "\"Thumbnail\": {"
|
| + "\"Url\": \"http://www.example.com/image/481989943\","
|
| + "\"Height\": 125,"
|
| + "\"Width\": \"100\""
|
| + "},"
|
| + "\"IDs\": [116, 943, 234, 38793]"
|
| + "}"
|
| + "}",
|
| + "{ 'usrf':[ 'utxt'(\"Image\"), { 'usrf':[ 'utxt'(\"Height\"), 600, "
|
| + "'utxt'(\"IDs\"), [ 116, 943, 234, 38793 ], 'utxt'(\"Thumbnail\"), "
|
| + "{ 'usrf':[ 'utxt'(\"Height\"), 125, 'utxt'(\"Url\"), "
|
| + "'utxt'(\"http://www.example.com/image/481989943\"), 'utxt'(\"Width\"), "
|
| + "'utxt'(\"100\") ] }, 'utxt'(\"Title\"), "
|
| + "'utxt'(\"View from 15th Floor\"), 'utxt'(\"Width\"), 800 ] } ] }",
|
| + typeAERecord },
|
| + { "["
|
| + "{"
|
| + "\"precision\": \"zip\","
|
| + "\"Latitude\": 37.7668,"
|
| + "\"Longitude\": -122.3959,"
|
| + "\"Address\": \"\","
|
| + "\"City\": \"SAN FRANCISCO\","
|
| + "\"State\": \"CA\","
|
| + "\"Zip\": \"94107\","
|
| + "\"Country\": \"US\""
|
| + "},"
|
| + "{"
|
| + "\"precision\": \"zip\","
|
| + "\"Latitude\": 37.371991,"
|
| + "\"Longitude\": -122.026020,"
|
| + "\"Address\": \"\","
|
| + "\"City\": \"SUNNYVALE\","
|
| + "\"State\": \"CA\","
|
| + "\"Zip\": \"94085\","
|
| + "\"Country\": \"US\""
|
| + "}"
|
| + "]",
|
| + "[ { 'usrf':[ 'utxt'(\"Address\"), 'utxt'(\"\"), 'utxt'(\"City\"), "
|
| + "'utxt'(\"SAN FRANCISCO\"), 'utxt'(\"Country\"), 'utxt'(\"US\"), "
|
| + "'utxt'(\"Latitude\"), 37.7668, 'utxt'(\"Longitude\"), -122.396, "
|
| + "'utxt'(\"State\"), 'utxt'(\"CA\"), 'utxt'(\"Zip\"), 'utxt'(\"94107\"), "
|
| + "'utxt'(\"precision\"), 'utxt'(\"zip\") ] }, { 'usrf':[ "
|
| + "'utxt'(\"Address\"), 'utxt'(\"\"), 'utxt'(\"City\"), "
|
| + "'utxt'(\"SUNNYVALE\"), 'utxt'(\"Country\"), 'utxt'(\"US\"), "
|
| + "'utxt'(\"Latitude\"), 37.372, 'utxt'(\"Longitude\"), -122.026, "
|
| + "'utxt'(\"State\"), 'utxt'(\"CA\"), 'utxt'(\"Zip\"), 'utxt'(\"94085\"), "
|
| + "'utxt'(\"precision\"), 'utxt'(\"zip\") ] } ]",
|
| + typeAEList },
|
| + };
|
| +
|
| + for (size_t i = 0; i < arraysize(cases); ++i) {
|
| + scoped_ptr<base::Value> value(base::JSONReader::Read(cases[i].json_input));
|
| + NSAppleEventDescriptor* descriptor =
|
| + ValueToAppleEventDescriptor(value.get());
|
| + NSString* descriptor_description = [descriptor description];
|
| +
|
| + std::string expected_contents =
|
| + base::StringPrintf("<NSAppleEventDescriptor: %s>",
|
| + cases[i].expected_aedesc_dump);
|
| + EXPECT_STREQ(expected_contents.c_str(),
|
| + [descriptor_description UTF8String]) << "i: " << i;
|
| + EXPECT_EQ(cases[i].expected_aedesc_type,
|
| + [descriptor descriptorType]) << "i: " << i;
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
|
|