Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / sync / util / get_session_name_unittest.cc
blob724cd8b7f69c9a33a3c9d6e76a0bdc4b99dba62e
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.
5 #include <string>
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/sys_info.h"
10 #include "sync/util/get_session_name.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 #if defined(OS_CHROMEOS)
14 #include "base/command_line.h"
15 #include "chromeos/chromeos_switches.h"
16 #endif // OS_CHROMEOS
18 namespace syncer {
20 namespace {
22 class GetSessionNameTest : public ::testing::Test {
23 public:
24 void SetSessionNameAndQuit(const std::string& session_name) {
25 session_name_ = session_name;
26 message_loop_.Quit();
29 protected:
30 base::MessageLoop message_loop_;
31 std::string session_name_;
34 // Call GetSessionNameSynchronouslyForTesting and make sure its return
35 // value looks sane.
36 TEST_F(GetSessionNameTest, GetSessionNameSynchronously) {
37 const std::string& session_name = GetSessionNameSynchronouslyForTesting();
38 EXPECT_FALSE(session_name.empty());
41 #if defined(OS_CHROMEOS)
43 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type
44 // is "lumpy-signed-mp-v2keys" and make sure the return value is "Chromebook".
45 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebook) {
46 const char* kLsbRelease = "CHROMEOS_RELEASE_BOARD=lumpy-signed-mp-v2keys\n";
47 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
48 const std::string& session_name = GetSessionNameSynchronouslyForTesting();
49 EXPECT_EQ("Chromebook", session_name);
52 // Call GetSessionNameSynchronouslyForTesting on ChromeOS where the board type
53 // is "stumpy-signed-mp-v2keys" and make sure the return value is "Chromebox".
54 TEST_F(GetSessionNameTest, GetSessionNameSynchronouslyChromebox) {
55 const char* kLsbRelease = "CHROMEOS_RELEASE_BOARD=stumpy-signed-mp-v2keys\n";
56 base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time());
57 const std::string& session_name = GetSessionNameSynchronouslyForTesting();
58 EXPECT_EQ("Chromebox", session_name);
61 #endif // OS_CHROMEOS
63 // Calls GetSessionName and runs the message loop until it comes back
64 // with a session name. Makes sure the returned session name is equal
65 // to the return value of GetSessionNameSynchronouslyForTesting().
66 TEST_F(GetSessionNameTest, GetSessionName) {
67 GetSessionName(message_loop_.message_loop_proxy(),
68 base::Bind(&GetSessionNameTest::SetSessionNameAndQuit,
69 base::Unretained(this)));
70 message_loop_.Run();
71 EXPECT_EQ(session_name_, GetSessionNameSynchronouslyForTesting());
74 } // namespace
76 } // namespace syncer