[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / applescript / apple_event_util_unittest.mm
blob5b3644ff8dec359535e6f34a888aa2fef8a467ea
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.
5 #import "chrome/browser/ui/cocoa/applescript/apple_event_util.h"
7 #include "base/basictypes.h"
8 #include "base/json/json_reader.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/values.h"
11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
12 #include "testing/gtest_mac.h"
14 namespace {
16 class AppleEventUtilTest : public CocoaTest { };
18 struct TestCase {
19   const char* json_input;
20   const char* expected_aedesc_dump;
21   DescType expected_aedesc_type;
24 TEST_F(AppleEventUtilTest, DISABLED_ValueToAppleEventDescriptor) {
25   const struct TestCase cases[] = {
26     { "null",         "'msng'",             typeType },
27     { "-1000",        "-1000",              typeSInt32 },
28     { "0",            "0",                  typeSInt32 },
29     { "1000",         "1000",               typeSInt32 },
30     { "-1e100",       "-1e+100",            typeIEEE64BitFloatingPoint },
31     { "0.0",          "0",                  typeIEEE64BitFloatingPoint },
32     { "1e100",        "1e+100",             typeIEEE64BitFloatingPoint },
33     { "\"\"",         "'utxt'(\"\")",       typeUnicodeText },
34     { "\"string\"",   "'utxt'(\"string\")", typeUnicodeText },
35     { "{}",           "{ 'usrf':[  ] }",    typeAERecord },
36     { "[]",           "[  ]",               typeAEList },
37     { "{\"Image\": {"
38       "\"Width\": 800,"
39       "\"Height\": 600,"
40       "\"Title\": \"View from 15th Floor\","
41       "\"Thumbnail\": {"
42       "\"Url\": \"http://www.example.com/image/481989943\","
43       "\"Height\": 125,"
44       "\"Width\": \"100\""
45       "},"
46       "\"IDs\": [116, 943, 234, 38793]"
47       "}"
48       "}",
49       "{ 'usrf':[ 'utxt'(\"Image\"), { 'usrf':[ 'utxt'(\"Height\"), 600, "
50       "'utxt'(\"IDs\"), [ 116, 943, 234, 38793 ], 'utxt'(\"Thumbnail\"), "
51       "{ 'usrf':[ 'utxt'(\"Height\"), 125, 'utxt'(\"Url\"), "
52       "'utxt'(\"http://www.example.com/image/481989943\"), 'utxt'(\"Width\"), "
53       "'utxt'(\"100\") ] }, 'utxt'(\"Title\"), "
54       "'utxt'(\"View from 15th Floor\"), 'utxt'(\"Width\"), 800 ] } ] }",
55       typeAERecord },
56     { "["
57       "{"
58       "\"precision\": \"zip\","
59       "\"Latitude\": 37.7668,"
60       "\"Longitude\": -122.3959,"
61       "\"Address\": \"\","
62       "\"City\": \"SAN FRANCISCO\","
63       "\"State\": \"CA\","
64       "\"Zip\": \"94107\","
65       "\"Country\": \"US\""
66       "},"
67       "{"
68       "\"precision\": \"zip\","
69       "\"Latitude\": 37.371991,"
70       "\"Longitude\": -122.026020,"
71       "\"Address\": \"\","
72       "\"City\": \"SUNNYVALE\","
73       "\"State\": \"CA\","
74       "\"Zip\": \"94085\","
75       "\"Country\": \"US\""
76       "}"
77       "]",
78       "[ { 'usrf':[ 'utxt'(\"Address\"), 'utxt'(\"\"), 'utxt'(\"City\"), "
79       "'utxt'(\"SAN FRANCISCO\"), 'utxt'(\"Country\"), 'utxt'(\"US\"), "
80       "'utxt'(\"Latitude\"), 37.7668, 'utxt'(\"Longitude\"), -122.396, "
81       "'utxt'(\"State\"), 'utxt'(\"CA\"), 'utxt'(\"Zip\"), 'utxt'(\"94107\"), "
82       "'utxt'(\"precision\"), 'utxt'(\"zip\") ] }, { 'usrf':[ "
83       "'utxt'(\"Address\"), 'utxt'(\"\"), 'utxt'(\"City\"), "
84       "'utxt'(\"SUNNYVALE\"), 'utxt'(\"Country\"), 'utxt'(\"US\"), "
85       "'utxt'(\"Latitude\"), 37.372, 'utxt'(\"Longitude\"), -122.026, "
86       "'utxt'(\"State\"), 'utxt'(\"CA\"), 'utxt'(\"Zip\"), 'utxt'(\"94085\"), "
87       "'utxt'(\"precision\"), 'utxt'(\"zip\") ] } ]",
88       typeAEList },
89   };
91   for (size_t i = 0; i < arraysize(cases); ++i) {
92     scoped_ptr<base::Value> value(base::JSONReader::Read(cases[i].json_input));
93     NSAppleEventDescriptor* descriptor =
94         chrome::mac::ValueToAppleEventDescriptor(value.get());
95     NSString* descriptor_description = [descriptor description];
97     std::string expected_contents =
98         base::StringPrintf("<NSAppleEventDescriptor: %s>",
99                            cases[i].expected_aedesc_dump);
100     EXPECT_STREQ(expected_contents.c_str(),
101                  [descriptor_description UTF8String]) << "i: " << i;
102     EXPECT_EQ(cases[i].expected_aedesc_type,
103               [descriptor descriptorType]) << "i: " << i;
104   }
106   // Test boolean values separately because boolean NSAppleEventDescriptors
107   // return different values across different system versions when their
108   // -description method is called.
110   const bool all_bools[] = { true, false };
111   for (bool b : all_bools) {
112     base::FundamentalValue value(b);
113     NSAppleEventDescriptor* descriptor =
114         chrome::mac::ValueToAppleEventDescriptor(&value);
116     EXPECT_EQ(typeBoolean, [descriptor descriptorType]);
117     EXPECT_EQ(b, [descriptor booleanValue]);
118   }
121 }  // namespace