1// Copyright (c) 2011 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#include "base/basictypes.h" 6#include "chrome/installer/mini_installer/appid.h" 7#include "chrome/installer/mini_installer/configuration.h" 8#include "testing/gtest/include/gtest/gtest.h" 9 10using mini_installer::Configuration; 11 12class TestConfiguration : public Configuration { 13 public: 14 explicit TestConfiguration(const wchar_t* command_line) : Configuration() { 15 Initialize(command_line); 16 } 17 private: 18 void Initialize(const wchar_t* command_line) { 19 ASSERT_TRUE(InitializeFromCommandLine(command_line)); 20 } 21}; 22 23// Test that the operation type is CLEANUP iff --cleanup is on the cmdline. 24TEST(MiniInstallerConfigurationTest, Operation) { 25 EXPECT_EQ(Configuration::INSTALL_PRODUCT, 26 TestConfiguration(L"spam.exe").operation()); 27 EXPECT_EQ(Configuration::INSTALL_PRODUCT, 28 TestConfiguration(L"spam.exe --clean").operation()); 29 EXPECT_EQ(Configuration::INSTALL_PRODUCT, 30 TestConfiguration(L"spam.exe --cleanupthis").operation()); 31 32 EXPECT_EQ(Configuration::CLEANUP, 33 TestConfiguration(L"spam.exe --cleanup").operation()); 34 EXPECT_EQ(Configuration::CLEANUP, 35 TestConfiguration(L"spam.exe --cleanup now").operation()); 36} 37 38TEST(MiniInstallerConfigurationTest, Program) { 39 EXPECT_TRUE(NULL == mini_installer::Configuration().program()); 40 EXPECT_TRUE(std::wstring(L"spam.exe") == 41 TestConfiguration(L"spam.exe").program()); 42 EXPECT_TRUE(std::wstring(L"spam.exe") == 43 TestConfiguration(L"spam.exe --with args").program()); 44 EXPECT_TRUE(std::wstring(L"c:\\blaz\\spam.exe") == 45 TestConfiguration(L"c:\\blaz\\spam.exe --with args").program()); 46} 47 48TEST(MiniInstallerConfigurationTest, ArgumentCount) { 49 EXPECT_EQ(1, TestConfiguration(L"spam.exe").argument_count()); 50 EXPECT_EQ(2, TestConfiguration(L"spam.exe --foo").argument_count()); 51 EXPECT_EQ(3, TestConfiguration(L"spam.exe --foo --bar").argument_count()); 52} 53 54TEST(MiniInstallerConfigurationTest, CommandLine) { 55 static const wchar_t* const kCommandLines[] = { 56 L"", 57 L"spam.exe", 58 L"spam.exe --foo", 59 }; 60 for (size_t i = 0; i < arraysize(kCommandLines); ++i) { 61 EXPECT_TRUE(std::wstring(kCommandLines[i]) == 62 TestConfiguration(kCommandLines[i]).command_line()); 63 } 64} 65 66TEST(MiniInstallerConfigurationTest, ChromeAppGuid) { 67 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == 68 TestConfiguration(L"spam.exe").chrome_app_guid()); 69 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == 70 TestConfiguration(L"spam.exe --chrome").chrome_app_guid()); 71 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == 72 TestConfiguration(L"spam.exe --multi-install --chrome") 73 .chrome_app_guid()); 74 EXPECT_TRUE(std::wstring(google_update::kAppGuid) == 75 TestConfiguration(L"spam.exe --chrome-frame").chrome_app_guid()); 76 EXPECT_TRUE(std::wstring(google_update::kSxSAppGuid) == 77 TestConfiguration(L"spam.exe --chrome-sxs").chrome_app_guid()); 78} 79 80TEST(MiniInstallerConfigurationTest, HasChrome) { 81 EXPECT_TRUE(TestConfiguration(L"spam.exe").has_chrome()); 82 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome").has_chrome()); 83 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome") 84 .has_chrome()); 85 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-frame").has_chrome()); 86 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install").has_chrome()); 87} 88 89TEST(MiniInstallerConfigurationTest, HasChromeFrame) { 90 EXPECT_FALSE(TestConfiguration(L"spam.exe").has_chrome_frame()); 91 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").has_chrome_frame()); 92 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install --chrome") 93 .has_chrome_frame()); 94 EXPECT_TRUE(TestConfiguration(L"spam.exe --chrome-frame").has_chrome_frame()); 95 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome-frame") 96 .has_chrome_frame()); 97 EXPECT_FALSE(TestConfiguration(L"spam.exe --multi-install") 98 .has_chrome_frame()); 99} 100 101TEST(MiniInstallerConfigurationTest, IsMultiInstall) { 102 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_multi_install()); 103 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_multi_install()); 104 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome") 105 .is_multi_install()); 106 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome-frame") 107 .is_multi_install()); 108 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install --chrome-frame") 109 .is_multi_install()); 110 EXPECT_TRUE(TestConfiguration(L"spam.exe --multi-install") 111 .is_multi_install()); 112} 113 114TEST(MiniInstallerConfigurationTest, IsSystemLevel) { 115 EXPECT_FALSE(TestConfiguration(L"spam.exe").is_system_level()); 116 EXPECT_FALSE(TestConfiguration(L"spam.exe --chrome").is_system_level()); 117 EXPECT_TRUE(TestConfiguration(L"spam.exe --system-level").is_system_level()); 118} 119