Home | History | Annotate | Download | only in util
      1 // Copyright (c) 2012 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 <utility>
      6 
      7 #include "base/basictypes.h"
      8 #include "chrome/installer/util/channel_info.h"
      9 #include "chrome/installer/util/util_constants.h"
     10 #include "testing/gtest/include/gtest/gtest.h"
     11 
     12 using installer::ChannelInfo;
     13 
     14 namespace {
     15 
     16 const std::wstring kChannelStable(installer::kChromeChannelStable);
     17 const std::wstring kChannelBeta(installer::kChromeChannelBeta);
     18 const std::wstring kChannelDev(installer::kChromeChannelDev);
     19 
     20 }  // namespace
     21 
     22 TEST(ChannelInfoTest, Channels) {
     23   ChannelInfo ci;
     24   std::wstring channel;
     25 
     26   ci.set_value(L"");
     27   EXPECT_TRUE(ci.GetChannelName(&channel));
     28   EXPECT_EQ(kChannelStable, channel);
     29   ci.set_value(L"-full");
     30   EXPECT_TRUE(ci.GetChannelName(&channel));
     31   EXPECT_EQ(kChannelStable, channel);
     32 
     33   ci.set_value(L"2.0-beta");
     34   EXPECT_TRUE(ci.GetChannelName(&channel));
     35   EXPECT_EQ(kChannelBeta, channel);
     36   ci.set_value(L"2.0-beta-spam");
     37   EXPECT_TRUE(ci.GetChannelName(&channel));
     38   EXPECT_EQ(kChannelBeta, channel);
     39   ci.set_value(L"2.0-spam-beta");
     40   EXPECT_TRUE(ci.GetChannelName(&channel));
     41   EXPECT_EQ(kChannelBeta, channel);
     42 
     43   ci.set_value(L"2.0-dev");
     44   EXPECT_TRUE(ci.GetChannelName(&channel));
     45   EXPECT_EQ(kChannelDev, channel);
     46   ci.set_value(L"2.0-kinda-dev");
     47   EXPECT_TRUE(ci.GetChannelName(&channel));
     48   EXPECT_EQ(kChannelDev, channel);
     49   ci.set_value(L"2.0-dev-eloper");
     50   EXPECT_TRUE(ci.GetChannelName(&channel));
     51   EXPECT_EQ(kChannelDev, channel);
     52 
     53   ci.set_value(L"x64-dev");
     54   EXPECT_TRUE(ci.GetChannelName(&channel));
     55   EXPECT_EQ(kChannelDev, channel);
     56   ci.set_value(L"x64-beta");
     57   EXPECT_TRUE(ci.GetChannelName(&channel));
     58   EXPECT_EQ(kChannelBeta, channel);
     59   ci.set_value(L"x64-stable");
     60   EXPECT_TRUE(ci.GetChannelName(&channel));
     61   EXPECT_EQ(kChannelStable, channel);
     62 
     63   ci.set_value(L"fuzzy");
     64   EXPECT_FALSE(ci.GetChannelName(&channel));
     65 }
     66 
     67 TEST(ChannelInfoTest, FullInstall) {
     68   ChannelInfo ci;
     69 
     70   ci.set_value(L"");
     71   EXPECT_TRUE(ci.SetFullSuffix(true));
     72   EXPECT_TRUE(ci.HasFullSuffix());
     73   EXPECT_EQ(L"-full", ci.value());
     74   EXPECT_FALSE(ci.SetFullSuffix(true));
     75   EXPECT_TRUE(ci.HasFullSuffix());
     76   EXPECT_EQ(L"-full", ci.value());
     77   EXPECT_TRUE(ci.SetFullSuffix(false));
     78   EXPECT_FALSE(ci.HasFullSuffix());
     79   EXPECT_EQ(L"", ci.value());
     80   EXPECT_FALSE(ci.SetFullSuffix(false));
     81   EXPECT_FALSE(ci.HasFullSuffix());
     82   EXPECT_EQ(L"", ci.value());
     83 
     84   ci.set_value(L"2.0-beta");
     85   EXPECT_TRUE(ci.SetFullSuffix(true));
     86   EXPECT_TRUE(ci.HasFullSuffix());
     87   EXPECT_EQ(L"2.0-beta-full", ci.value());
     88   EXPECT_FALSE(ci.SetFullSuffix(true));
     89   EXPECT_TRUE(ci.HasFullSuffix());
     90   EXPECT_EQ(L"2.0-beta-full", ci.value());
     91   EXPECT_TRUE(ci.SetFullSuffix(false));
     92   EXPECT_FALSE(ci.HasFullSuffix());
     93   EXPECT_EQ(L"2.0-beta", ci.value());
     94   EXPECT_FALSE(ci.SetFullSuffix(false));
     95   EXPECT_FALSE(ci.HasFullSuffix());
     96   EXPECT_EQ(L"2.0-beta", ci.value());
     97 }
     98 
     99 TEST(ChannelInfoTest, MultiInstall) {
    100   ChannelInfo ci;
    101 
    102   ci.set_value(L"");
    103   EXPECT_TRUE(ci.SetMultiInstall(true));
    104   EXPECT_TRUE(ci.IsMultiInstall());
    105   EXPECT_EQ(L"-multi", ci.value());
    106   EXPECT_FALSE(ci.SetMultiInstall(true));
    107   EXPECT_TRUE(ci.IsMultiInstall());
    108   EXPECT_EQ(L"-multi", ci.value());
    109   EXPECT_TRUE(ci.SetMultiInstall(false));
    110   EXPECT_FALSE(ci.IsMultiInstall());
    111   EXPECT_EQ(L"", ci.value());
    112   EXPECT_FALSE(ci.SetMultiInstall(false));
    113   EXPECT_FALSE(ci.IsMultiInstall());
    114   EXPECT_EQ(L"", ci.value());
    115 
    116   ci.set_value(L"2.0-beta");
    117   EXPECT_TRUE(ci.SetMultiInstall(true));
    118   EXPECT_TRUE(ci.IsMultiInstall());
    119   EXPECT_EQ(L"2.0-beta-multi", ci.value());
    120   EXPECT_FALSE(ci.SetMultiInstall(true));
    121   EXPECT_TRUE(ci.IsMultiInstall());
    122   EXPECT_EQ(L"2.0-beta-multi", ci.value());
    123   EXPECT_TRUE(ci.SetMultiInstall(false));
    124   EXPECT_FALSE(ci.IsMultiInstall());
    125   EXPECT_EQ(L"2.0-beta", ci.value());
    126   EXPECT_FALSE(ci.SetMultiInstall(false));
    127   EXPECT_FALSE(ci.IsMultiInstall());
    128   EXPECT_EQ(L"2.0-beta", ci.value());
    129 }
    130 
    131 TEST(ChannelInfoTest, Migration) {
    132   ChannelInfo ci;
    133 
    134   ci.set_value(L"");
    135   EXPECT_TRUE(ci.SetMigratingSuffix(true));
    136   EXPECT_TRUE(ci.HasMigratingSuffix());
    137   EXPECT_EQ(L"-migrating", ci.value());
    138   EXPECT_FALSE(ci.SetMigratingSuffix(true));
    139   EXPECT_TRUE(ci.HasMigratingSuffix());
    140   EXPECT_EQ(L"-migrating", ci.value());
    141   EXPECT_TRUE(ci.SetMigratingSuffix(false));
    142   EXPECT_FALSE(ci.HasMigratingSuffix());
    143   EXPECT_EQ(L"", ci.value());
    144   EXPECT_FALSE(ci.SetMigratingSuffix(false));
    145   EXPECT_FALSE(ci.HasMigratingSuffix());
    146   EXPECT_EQ(L"", ci.value());
    147 
    148   ci.set_value(L"2.0-beta");
    149   EXPECT_TRUE(ci.SetMigratingSuffix(true));
    150   EXPECT_TRUE(ci.HasMigratingSuffix());
    151   EXPECT_EQ(L"2.0-beta-migrating", ci.value());
    152   EXPECT_FALSE(ci.SetMigratingSuffix(true));
    153   EXPECT_TRUE(ci.HasMigratingSuffix());
    154   EXPECT_EQ(L"2.0-beta-migrating", ci.value());
    155   EXPECT_TRUE(ci.SetMigratingSuffix(false));
    156   EXPECT_FALSE(ci.HasMigratingSuffix());
    157   EXPECT_EQ(L"2.0-beta", ci.value());
    158   EXPECT_FALSE(ci.SetMigratingSuffix(false));
    159   EXPECT_FALSE(ci.HasMigratingSuffix());
    160   EXPECT_EQ(L"2.0-beta", ci.value());
    161 }
    162 
    163 TEST(ChannelInfoTest, Combinations) {
    164   ChannelInfo ci;
    165 
    166   ci.set_value(L"2.0-beta-chromeframe");
    167   EXPECT_FALSE(ci.IsChrome());
    168   ci.set_value(L"2.0-beta-chromeframe-chrome");
    169   EXPECT_TRUE(ci.IsChrome());
    170 }
    171 
    172 TEST(ChannelInfoTest, GetStage) {
    173   ChannelInfo ci;
    174 
    175   ci.set_value(L"");
    176   EXPECT_EQ(L"", ci.GetStage());
    177   ci.set_value(L"-stage");
    178   EXPECT_EQ(L"", ci.GetStage());
    179   ci.set_value(L"-stage:");
    180   EXPECT_EQ(L"", ci.GetStage());
    181   ci.set_value(L"-stage:spammy");
    182   EXPECT_EQ(L"spammy", ci.GetStage());
    183 
    184   ci.set_value(L"-multi");
    185   EXPECT_EQ(L"", ci.GetStage());
    186   ci.set_value(L"-stage-multi");
    187   EXPECT_EQ(L"", ci.GetStage());
    188   ci.set_value(L"-stage:-multi");
    189   EXPECT_EQ(L"", ci.GetStage());
    190   ci.set_value(L"-stage:spammy-multi");
    191   EXPECT_EQ(L"spammy", ci.GetStage());
    192 
    193   ci.set_value(L"2.0-beta-multi");
    194   EXPECT_EQ(L"", ci.GetStage());
    195   ci.set_value(L"2.0-beta-stage-multi");
    196   EXPECT_EQ(L"", ci.GetStage());
    197   ci.set_value(L"2.0-beta-stage:-multi");
    198   EXPECT_EQ(L"", ci.GetStage());
    199   ci.set_value(L"2.0-beta-stage:spammy-multi");
    200   EXPECT_EQ(L"spammy", ci.GetStage());
    201 }
    202 
    203 TEST(ChannelInfoTest, SetStage) {
    204   ChannelInfo ci;
    205 
    206   ci.set_value(L"");
    207   EXPECT_FALSE(ci.SetStage(NULL));
    208   EXPECT_EQ(L"", ci.value());
    209   EXPECT_TRUE(ci.SetStage(L"spammy"));
    210   EXPECT_EQ(L"-stage:spammy", ci.value());
    211   EXPECT_FALSE(ci.SetStage(L"spammy"));
    212   EXPECT_EQ(L"-stage:spammy", ci.value());
    213   EXPECT_TRUE(ci.SetStage(NULL));
    214   EXPECT_EQ(L"", ci.value());
    215   EXPECT_TRUE(ci.SetStage(L"spammy"));
    216   EXPECT_TRUE(ci.SetStage(L""));
    217   EXPECT_EQ(L"", ci.value());
    218 
    219   ci.set_value(L"-multi");
    220   EXPECT_FALSE(ci.SetStage(NULL));
    221   EXPECT_EQ(L"-multi", ci.value());
    222   EXPECT_TRUE(ci.SetStage(L"spammy"));
    223   EXPECT_EQ(L"-stage:spammy-multi", ci.value());
    224   EXPECT_FALSE(ci.SetStage(L"spammy"));
    225   EXPECT_EQ(L"-stage:spammy-multi", ci.value());
    226   EXPECT_TRUE(ci.SetStage(NULL));
    227   EXPECT_EQ(L"-multi", ci.value());
    228   EXPECT_TRUE(ci.SetStage(L"spammy"));
    229   EXPECT_TRUE(ci.SetStage(L""));
    230   EXPECT_EQ(L"-multi", ci.value());
    231 
    232   ci.set_value(L"2.0-beta-multi");
    233   EXPECT_FALSE(ci.SetStage(NULL));
    234   EXPECT_EQ(L"2.0-beta-multi", ci.value());
    235   EXPECT_TRUE(ci.SetStage(L"spammy"));
    236   EXPECT_EQ(L"2.0-beta-stage:spammy-multi", ci.value());
    237   EXPECT_FALSE(ci.SetStage(L"spammy"));
    238   EXPECT_EQ(L"2.0-beta-stage:spammy-multi", ci.value());
    239   EXPECT_TRUE(ci.SetStage(NULL));
    240   EXPECT_EQ(L"2.0-beta-multi", ci.value());
    241   EXPECT_TRUE(ci.SetStage(L"spammy"));
    242   EXPECT_TRUE(ci.SetStage(L""));
    243   EXPECT_EQ(L"2.0-beta-multi", ci.value());
    244 
    245   ci.set_value(L"2.0-beta-stage:-multi");
    246   EXPECT_TRUE(ci.SetStage(NULL));
    247   EXPECT_EQ(L"2.0-beta-multi", ci.value());
    248 }
    249 
    250 TEST(ChannelInfoTest, RemoveAllModifiersAndSuffixes) {
    251   ChannelInfo ci;
    252 
    253   ci.set_value(L"");
    254   EXPECT_FALSE(ci.RemoveAllModifiersAndSuffixes());
    255   EXPECT_EQ(L"", ci.value());
    256 
    257   ci.set_value(L"2.0-dev-multi-chrome-chromeframe-migrating");
    258   EXPECT_TRUE(ci.RemoveAllModifiersAndSuffixes());
    259   EXPECT_EQ(L"2.0-dev", ci.value());
    260 }
    261