[email protected] | 96613eb9 | 2009-06-30 22:14:37 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | 8bcdcbe8 | 2008-08-18 21:39:43 | [diff] [blame] | 4 | // |
| 5 | // Unit tests for GoogleChromeDistribution class. |
| 6 | |
| 7 | #include <windows.h> |
| 8 | |
[email protected] | d9b1687 | 2008-09-09 23:07:24 | [diff] [blame] | 9 | #include "base/scoped_ptr.h" |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 10 | #include "chrome/common/json_value_serializer.h" |
[email protected] | 8bcdcbe8 | 2008-08-18 21:39:43 | [diff] [blame] | 11 | #include "chrome/installer/util/browser_distribution.h" |
[email protected] | d9b1687 | 2008-09-09 23:07:24 | [diff] [blame] | 12 | #include "chrome/installer/util/google_update_constants.h" |
[email protected] | 8bcdcbe8 | 2008-08-18 21:39:43 | [diff] [blame] | 13 | #include "chrome/installer/util/google_chrome_distribution.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
[email protected] | bb725dc7 | 2010-06-10 03:17:41 | [diff] [blame] | 16 | #if defined(GOOGLE_CHROME_BUILD) |
[email protected] | f216f98 | 2010-06-12 23:43:09 | [diff] [blame] | 17 | TEST(GoogleChromeDistTest, TestExtractUninstallMetrics) { |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 18 | // A make-believe JSON preferences file. |
| 19 | std::string pref_string( |
| 20 | "{ \n" |
| 21 | " \"foo\": \"bar\",\n" |
| 22 | " \"uninstall_metrics\": { \n" |
| 23 | " \"last_launch_time_sec\": \"1235341118\"," |
| 24 | " \"last_observed_running_time_sec\": \"1235341183\"," |
| 25 | " \"launch_count\": \"11\"," |
| 26 | " \"page_load_count\": \"68\"," |
[email protected] | 6b5f21d | 2009-04-13 17:01:35 | [diff] [blame] | 27 | " \"uptime_sec\": \"809\"," |
| 28 | " \"installation_date2\": \"1235341141\"\n" |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 29 | " },\n" |
| 30 | " \"blah\": {\n" |
| 31 | " \"this_sentence_is_true\": false\n" |
| 32 | " },\n" |
| 33 | " \"user_experience_metrics\": { \n" |
| 34 | " \"client_id_timestamp\": \"1234567890\"," |
| 35 | " \"reporting_enabled\": true\n" |
| 36 | " }\n" |
| 37 | "} \n"); |
| 38 | |
| 39 | // The URL string we expect to be generated from said make-believe file. |
| 40 | std::wstring expected_url_string( |
[email protected] | 6b5f21d | 2009-04-13 17:01:35 | [diff] [blame] | 41 | L"&installation_date2=1235341141" |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 42 | L"&last_launch_time_sec=1235341118" |
| 43 | L"&last_observed_running_time_sec=1235341183" |
[email protected] | 6b5f21d | 2009-04-13 17:01:35 | [diff] [blame] | 44 | L"&launch_count=11&page_load_count=68" |
| 45 | L"&uptime_sec=809"); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 46 | |
| 47 | JSONStringValueSerializer json_deserializer(pref_string); |
| 48 | std::string error_message; |
| 49 | |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 50 | scoped_ptr<Value> root(json_deserializer.Deserialize(NULL, &error_message)); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 51 | ASSERT_TRUE(root.get()); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 52 | std::wstring uninstall_metrics_string; |
| 53 | GoogleChromeDistribution* dist = static_cast<GoogleChromeDistribution*>( |
| 54 | BrowserDistribution::GetDistribution()); |
[email protected] | f216f98 | 2010-06-12 23:43:09 | [diff] [blame] | 55 | |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 56 | EXPECT_TRUE( |
| 57 | dist->ExtractUninstallMetrics(*static_cast<DictionaryValue*>(root.get()), |
| 58 | &uninstall_metrics_string)); |
| 59 | EXPECT_EQ(expected_url_string, uninstall_metrics_string); |
| 60 | } |
[email protected] | f216f98 | 2010-06-12 23:43:09 | [diff] [blame] | 61 | #endif // defined(GOOGLE_CHROME_BUILD) |