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

Side by Side Diff: blimp/engine/app/blimp_engine_config_unittest.cc

Issue 2629743003: Remove all blimp engine code (Closed)
Patch Set: Use consistent comment style in //chrome Created 3 years, 11 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
« no previous file with comments | « blimp/engine/app/blimp_engine_config.cc ('k') | blimp/engine/app/blimp_engine_crash_keys.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "blimp/engine/app/blimp_engine_config.h"
6
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 #include "base/command_line.h"
12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h"
14 #include "base/strings/stringprintf.h"
15 #include "blimp/common/switches.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace blimp {
19 namespace engine {
20 namespace {
21
22 // Reference client token.
23 static const char kTestClientAuthToken[] = "Reference client token";
24
25 class BlimpEngineConfigTest : public testing::Test {
26 protected:
27 void SetUp() override {
28 // Create a temporary directory and populate it with all of the switches
29 // If a test requires a switch's file to be missing, call
30 // RemoveFileForSwitch().
31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32 CreateFileForSwitch(kClientAuthTokenPath, kTestClientAuthToken);
33 }
34
35 // Creates a file in the temp directory for a given filepath switch.
36 void CreateFileForSwitch(const std::string& filepath_switch,
37 const std::string& data) const {
38 ASSERT_TRUE(base::WriteFile(GetFilepathForSwitch(filepath_switch),
39 data.c_str(), data.size()));
40 }
41
42 // Removes the associated file for a given filepath switch.
43 void RemoveFileForSwitch(const std::string& filepath_switch) const {
44 base::DeleteFile(GetFilepathForSwitch(filepath_switch), false);
45 }
46
47 // Creates and returns a CommandLine object with specified filepath switches.
48 base::CommandLine CreateCommandLine(
49 const std::vector<std::string>& filepath_switches) {
50 base::CommandLine::StringVector cmd_vec = {"dummy_program"};
51 for (const std::string& filepath_switch : filepath_switches) {
52 cmd_vec.push_back(base::StringPrintf(
53 "--%s=%s", filepath_switch.c_str(),
54 GetFilepathForSwitch(filepath_switch).AsUTF8Unsafe().c_str()));
55 }
56 return base::CommandLine(cmd_vec);
57 }
58
59 base::FilePath GetFilepathForSwitch(
60 const std::string& filepath_switch) const {
61 return temp_dir_.GetPath().Append(filepath_switch);
62 }
63
64 const std::vector<std::string> all_filepath_switches_ = {
65 kClientAuthTokenPath};
66
67 base::ScopedTempDir temp_dir_;
68 };
69
70 TEST_F(BlimpEngineConfigTest, ClientAuthTokenCorrect) {
71 auto cmd_line = CreateCommandLine(all_filepath_switches_);
72 auto engine_config = BlimpEngineConfig::Create(cmd_line);
73 EXPECT_NE(nullptr, engine_config);
74 EXPECT_EQ(kTestClientAuthToken, engine_config->client_auth_token());
75 }
76
77 TEST_F(BlimpEngineConfigTest, ClientAuthTokenEmpty) {
78 RemoveFileForSwitch(kClientAuthTokenPath);
79 CreateFileForSwitch(kClientAuthTokenPath, " ");
80 auto cmd_line = CreateCommandLine(all_filepath_switches_);
81 auto engine_config = BlimpEngineConfig::Create(cmd_line);
82 EXPECT_EQ(nullptr, engine_config);
83 }
84
85 } // namespace
86 } // namespace engine
87 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/engine/app/blimp_engine_config.cc ('k') | blimp/engine/app/blimp_engine_crash_keys.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698