blob: 1e0ede8a9a1f868d46b6240c2d2f520319c216ab [file] [log] [blame]
[email protected]96613eb92009-06-30 22:14:371// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]8bcdcbe82008-08-18 21:39:434//
5// Unit tests for GoogleChromeDistribution class.
6
7#include <windows.h>
8
[email protected]d9b16872008-09-09 23:07:249#include "base/scoped_ptr.h"
[email protected]0bb1a622009-03-04 03:22:3210#include "chrome/common/json_value_serializer.h"
[email protected]8bcdcbe82008-08-18 21:39:4311#include "chrome/installer/util/browser_distribution.h"
[email protected]d9b16872008-09-09 23:07:2412#include "chrome/installer/util/google_update_constants.h"
[email protected]8bcdcbe82008-08-18 21:39:4313#include "chrome/installer/util/google_chrome_distribution.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
[email protected]bb725dc72010-06-10 03:17:4116#if defined(GOOGLE_CHROME_BUILD)
[email protected]f216f982010-06-12 23:43:0917TEST(GoogleChromeDistTest, TestExtractUninstallMetrics) {
[email protected]0bb1a622009-03-04 03:22:3218 // 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]6b5f21d2009-04-13 17:01:3527 " \"uptime_sec\": \"809\","
28 " \"installation_date2\": \"1235341141\"\n"
[email protected]0bb1a622009-03-04 03:22:3229 " },\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]6b5f21d2009-04-13 17:01:3541 L"&installation_date2=1235341141"
[email protected]0bb1a622009-03-04 03:22:3242 L"&last_launch_time_sec=1235341118"
43 L"&last_observed_running_time_sec=1235341183"
[email protected]6b5f21d2009-04-13 17:01:3544 L"&launch_count=11&page_load_count=68"
45 L"&uptime_sec=809");
[email protected]0bb1a622009-03-04 03:22:3246
47 JSONStringValueSerializer json_deserializer(pref_string);
48 std::string error_message;
49
[email protected]ba399672010-04-06 15:42:3950 scoped_ptr<Value> root(json_deserializer.Deserialize(NULL, &error_message));
[email protected]0bb1a622009-03-04 03:22:3251 ASSERT_TRUE(root.get());
[email protected]0bb1a622009-03-04 03:22:3252 std::wstring uninstall_metrics_string;
53 GoogleChromeDistribution* dist = static_cast<GoogleChromeDistribution*>(
54 BrowserDistribution::GetDistribution());
[email protected]f216f982010-06-12 23:43:0955
[email protected]0bb1a622009-03-04 03:22:3256 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]f216f982010-06-12 23:43:0961#endif // defined(GOOGLE_CHROME_BUILD)