Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: chrome/installer/setup/install_unittest.cc

Issue 10160011: Create VisualElementsManifest.xml from template -- install VisualElements in the version directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: untested tests... Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 <string>
6
7 #include "base/file_util.h"
8 #include "base/platform_file.h"
9 #include "base/scoped_temp_dir.h"
10 #include "base/version.h"
11 #include "chrome/installer/setup/install.h"
12 #include "chrome/installer/setup/setup_constants.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 class InstallTest : public testing::Test {
18 protected:
19 virtual void SetUp() {
grt (UTC plus 2) 2012/05/04 13:19:14 SetUp() OVERRIDE {
gab 2012/05/04 17:26:35 Interesting, I copied the format from setup_util_u
20 // Create a temp directory for testing.
21 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
22 }
23
24 virtual void TearDown() {
grt (UTC plus 2) 2012/05/04 13:19:14 TearDown() OVERRIDE {
gab 2012/05/04 17:26:35 Done.
25 // Clean up test directory manually so we can fail if it leaks.
26 ASSERT_TRUE(test_dir_.Delete());
27 }
28
29 // Initializes InstallTest variables for tests testing
30 // installer::CreateVisualElementsManifest
31 void InitVisualElementsTest(bool create_elements_folder) {
grt (UTC plus 2) 2012/05/04 13:19:14 move everything in this function through line 43 i
gab 2012/05/04 17:26:35 Done.
32 work_dir_ = test_dir_.path();
33 ASSERT_TRUE(file_util::PathExists(work_dir_));
grt (UTC plus 2) 2012/05/04 13:19:14 there's no need to check this since the assert on
gab 2012/05/04 17:26:35 Done.
34
35 version_ = Version("0.0.0.0");
36
37 version_dir_ = work_dir_.AppendASCII(version_.GetString());
38 ASSERT_FALSE(file_util::PathExists(version_dir_));
grt (UTC plus 2) 2012/05/04 13:19:14 there's no need to check for this since test_dir_
gab 2012/05/04 17:26:35 Done.
39 EXPECT_TRUE(file_util::CreateDirectory(version_dir_));
40 ASSERT_TRUE(file_util::PathExists(version_dir_));
grt (UTC plus 2) 2012/05/04 13:19:14 there's no need to check for this since we assume
gab 2012/05/04 17:26:35 Done.
41
42 elements_dir_ = version_dir_.Append(installer::kVisualElements);
43 ASSERT_FALSE(file_util::PathExists(elements_dir_));
grt (UTC plus 2) 2012/05/04 13:19:14 remove this, too.
gab 2012/05/04 17:26:35 Done.
44 if (create_elements_folder) {
grt (UTC plus 2) 2012/05/04 13:19:14 move directory creation into VisualElementsManifes
gab 2012/05/04 17:26:35 Done.
45 EXPECT_TRUE(file_util::CreateDirectory(elements_dir_));
46 ASSERT_TRUE(file_util::PathExists(elements_dir_));
47 }
48 }
49
50 // The path to |test_dir_|.
51 FilePath work_dir_;
grt (UTC plus 2) 2012/05/04 13:19:14 remove this and use test_dir_.path() where needed
gab 2012/05/04 17:26:35 Done.
52
53 // A dummy version number used to create the version directory.
54 Version version_;
55
56 // The path to |work_dir_|\|version_|.
57 FilePath version_dir_;
58
59 // The path to |version_dir_|\VisualElements.
60 FilePath elements_dir_;
61
62 private:
grt (UTC plus 2) 2012/05/04 13:19:14 i was motivated by a reviewer long ago to make eve
gab 2012/05/04 17:26:35 Done.
63 // The temporary directory used to contain the test operations.
64 ScopedTempDir test_dir_;
65 };
66
67 } // namespace
68
69 // Test that VisualElementsManifest.xml is not created when VisualElements are
70 // not present.
71 TEST_F(InstallTest, VisualElementsManifestNotCreated) {
72 InitVisualElementsTest(false);
73 EXPECT_TRUE(installer::CreateVisualElementsManifest(work_dir_, version_));
74 EXPECT_FALSE(file_util::PathExists(
75 work_dir_.Append(installer::kVisualElementsManifest)));
76 }
77
78 // Test that VisualElementsManifest.xml is created with the correct content when
79 // VisualElements are present.
80 TEST_F(InstallTest, VisualElementsManifestCreated) {
81 InitVisualElementsTest(true);
82 EXPECT_TRUE(installer::CreateVisualElementsManifest(work_dir_, version_));
83 const FilePath manifest_path(
grt (UTC plus 2) 2012/05/04 13:19:14 since this path is used by both tests, i think it
gab 2012/05/04 17:26:35 Done.
84 work_dir_.Append(installer::kVisualElementsManifest));
85 EXPECT_TRUE(file_util::PathExists(manifest_path));
86
87 std::string read_manifest;
88 file_util::ReadFileToString(manifest_path, &read_manifest);
grt (UTC plus 2) 2012/05/04 13:19:14 ASSERT_TRUE?
gab 2012/05/04 17:26:35 Done.
89
90 static const char kExpectedManifest[] =
91 "<Application>\r\n"
92 " <VisualElements\r\n"
93 " DisplayName='Google Chrome'\r\n"
94 " Logo='0.0.0.0\\VisualElements\\Logo.png'\r\n"
95 " SmallLogo='0.0.0.0\\VisualElements\\SmallLogo.png'\r\n"
96 " ForegroundText='light'\r\n"
97 " BackgroundColor='white'>\r\n"
98 " <DefaultTile ShowName='allLogos'/>\r\n"
99 " <SplashScreen Image='0.0.0.0\\VisualElements\\splash-620x300.png'/>"
grt (UTC plus 2) 2012/05/04 13:19:14 does this wrap more nicely if you break it just af
gab 2012/05/04 17:26:35 Ya I guess, wasn't sure where to break it...
100 "\r\n"
101 " </VisualElements>\r\n"
102 "</Application>";
103
104 EXPECT_STREQ(kExpectedManifest, read_manifest.c_str());
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698