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

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

Issue 1958033003: Allows client to access auth token from command line specified file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/engine/app/blimp_engine_config.h" 5 #include "blimp/engine/app/blimp_engine_config.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "blimp/common/fake_commandline.h"
Kevin M 2016/05/10 18:06:35 Not used?
CJ 2016/05/10 20:58:07 Was being used for CreateCommandLine, but since we
15 #include "blimp/engine/app/switches.h" 16 #include "blimp/engine/app/switches.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace blimp { 19 namespace blimp {
19 namespace engine { 20 namespace engine {
20 namespace { 21 namespace {
21 22
22 // Reference client token.
23 static const char kTestClientToken[] = "Reference client token"; 23 static const char kTestClientToken[] = "Reference client token";
24 24
25 class BlimpEngineConfigTest : public testing::Test { 25 class BlimpEngineConfigTest : public testing::Test {
26 protected: 26 protected:
27 void SetUp() override { 27 void SetUp() override {
28 // Create a temporary directory and populate it with all of the switches 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 29 // If a test requires a switch's file to be missing, call
30 // RemoveFileForSwitch(). 30 // RemoveFileForSwitch().
31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 31 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32 CreateFileForSwitch(kClientTokenPath, kTestClientToken); 32 CreateFileForSwitch(kClientTokenPath, kTestClientToken);
33 } 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_.path().Append(filepath_switch);
62 }
63
64 const std::vector<std::string> all_filepath_switches_ = {kClientTokenPath};
65
66 base::ScopedTempDir temp_dir_;
67 }; 34 };
68 35
69 TEST_F(BlimpEngineConfigTest, ClientTokenCorrect) { 36 TEST_F(BlimpEngineConfigTest, ClientTokenCorrect) {
70 auto cmd_line = CreateCommandLine(all_filepath_switches_); 37 auto cmd_line = CreateCommandLine(all_filepath_switches_);
Kevin M 2016/05/10 18:06:35 As in assignment_source_unittest, reference the te
CJ 2016/05/10 20:58:06 Acknowledged.
71 auto engine_config = BlimpEngineConfig::Create(cmd_line); 38 auto engine_config = BlimpEngineConfig::Create(cmd_line);
72 EXPECT_NE(nullptr, engine_config); 39 EXPECT_NE(nullptr, engine_config);
73 EXPECT_EQ(kTestClientToken, engine_config->client_token()); 40 EXPECT_EQ(kTestClientToken, engine_config->client_token());
74 } 41 }
75 42
76 TEST_F(BlimpEngineConfigTest, ClientTokenEmpty) { 43 TEST_F(BlimpEngineConfigTest, ClientTokenEmpty) {
77 RemoveFileForSwitch(kClientTokenPath); 44 RemoveFileForSwitch(kClientTokenPath);
78 CreateFileForSwitch(kClientTokenPath, " "); 45 CreateFileForSwitch(kClientTokenPath, " ");
79 auto cmd_line = CreateCommandLine(all_filepath_switches_); 46 auto cmd_line = CreateCommandLine(all_filepath_switches_);
80 auto engine_config = BlimpEngineConfig::Create(cmd_line); 47 auto engine_config = BlimpEngineConfig::Create(cmd_line);
81 EXPECT_EQ(nullptr, engine_config); 48 EXPECT_EQ(nullptr, engine_config);
82 } 49 }
83 50
84 } // namespace 51 } // namespace
85 } // namespace engine 52 } // namespace engine
86 } // namespace blimp 53 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698