| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <atlbase.h> | 5 #include <atlbase.h> |
| 6 #include <atlcom.h> | 6 #include <atlcom.h> |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/win/scoped_comptr.h" | 10 #include "base/win/scoped_comptr.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 virtual void SetUp() { | 24 virtual void SetUp() { |
| 25 DeleteAllSingletons(); | 25 DeleteAllSingletons(); |
| 26 PathService::Get(base::DIR_SOURCE_ROOT, &test_file_path_); | 26 PathService::Get(base::DIR_SOURCE_ROOT, &test_file_path_); |
| 27 test_file_path_ = test_file_path_.Append(FILE_PATH_LITERAL("chrome_frame")) | 27 test_file_path_ = test_file_path_.Append(FILE_PATH_LITERAL("chrome_frame")) |
| 28 .Append(FILE_PATH_LITERAL("test")) | 28 .Append(FILE_PATH_LITERAL("test")) |
| 29 .Append(FILE_PATH_LITERAL("data")); | 29 .Append(FILE_PATH_LITERAL("data")); |
| 30 } | 30 } |
| 31 | 31 |
| 32 bool ReadFileAsString(const wchar_t* file_name, std::string* file_contents) { | 32 bool ReadFileAsString(const wchar_t* file_name, std::string* file_contents) { |
| 33 EXPECT_TRUE(file_name); | 33 EXPECT_TRUE(file_name); |
| 34 FilePath file_path = test_file_path_.Append(file_name); | 34 base::FilePath file_path = test_file_path_.Append(file_name); |
| 35 return file_util::ReadFileToString(file_path, file_contents); | 35 return file_util::ReadFileToString(file_path, file_contents); |
| 36 } | 36 } |
| 37 | 37 |
| 38 static bool StringToStream(const std::string& data, IStream** ret) { | 38 static bool StringToStream(const std::string& data, IStream** ret) { |
| 39 EXPECT_TRUE(!data.empty()); | 39 EXPECT_TRUE(!data.empty()); |
| 40 | 40 |
| 41 base::win::ScopedComPtr<IStream> stream; | 41 base::win::ScopedComPtr<IStream> stream; |
| 42 HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, stream.Receive()); | 42 HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, stream.Receive()); |
| 43 EXPECT_HRESULT_SUCCEEDED(hr); | 43 EXPECT_HRESULT_SUCCEEDED(hr); |
| 44 if (FAILED(hr)) { | 44 if (FAILED(hr)) { |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 DWORD written = 0; | 48 DWORD written = 0; |
| 49 hr = stream->Write(data.c_str(), data.size(), &written); | 49 hr = stream->Write(data.c_str(), data.size(), &written); |
| 50 EXPECT_HRESULT_SUCCEEDED(hr); | 50 EXPECT_HRESULT_SUCCEEDED(hr); |
| 51 EXPECT_EQ(data.size(), written); | 51 EXPECT_EQ(data.size(), written); |
| 52 | 52 |
| 53 bool result = false; | 53 bool result = false; |
| 54 if (SUCCEEDED(hr)) { | 54 if (SUCCEEDED(hr)) { |
| 55 RewindStream(stream); | 55 RewindStream(stream); |
| 56 *ret = stream.Detach(); | 56 *ret = stream.Detach(); |
| 57 result = true; | 57 result = true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 return result; | 60 return result; |
| 61 } | 61 } |
| 62 | 62 |
| 63 FilePath test_file_path_; | 63 base::FilePath test_file_path_; |
| 64 ScopedVirtualizeHklmAndHkcu virtualized_registry_; | 64 ScopedVirtualizeHklmAndHkcu virtualized_registry_; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 // Tests the CacheStream class by writing content into a stream object | 67 // Tests the CacheStream class by writing content into a stream object |
| 68 // and verify that reading that stream back | 68 // and verify that reading that stream back |
| 69 TEST_F(MonikerPatchTest, CacheStream) { | 69 TEST_F(MonikerPatchTest, CacheStream) { |
| 70 const char data[] = "ReadStreamCacheTest"; | 70 const char data[] = "ReadStreamCacheTest"; |
| 71 char ret[2 * sizeof(data)] = {0}; | 71 char ret[2 * sizeof(data)] = {0}; |
| 72 DWORD read = 0; | 72 DWORD read = 0; |
| 73 | 73 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 244 |
| 245 std::string data_read; | 245 std::string data_read; |
| 246 data_read.append(read_buffer1.get(), read_size1); | 246 data_read.append(read_buffer1.get(), read_size1); |
| 247 data_read.append(read_buffer2.get(), read_size2); | 247 data_read.append(read_buffer2.get(), read_size2); |
| 248 EXPECT_EQ(small_html_meta_tag, data_read); | 248 EXPECT_EQ(small_html_meta_tag, data_read); |
| 249 | 249 |
| 250 EXPECT_EQ(S_FALSE, ret3); | 250 EXPECT_EQ(S_FALSE, ret3); |
| 251 EXPECT_STREQ("", read_buffer3); | 251 EXPECT_STREQ("", read_buffer3); |
| 252 EXPECT_EQ(sizeof(read_buffer3), read_size3); | 252 EXPECT_EQ(sizeof(read_buffer3), read_size3); |
| 253 } | 253 } |
| OLD | NEW |