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

Side by Side Diff: chrome/browser/extensions/api/log_private/log_private_apitest_chromeos.cc

Issue 329853010: Additional methods for chrome.logPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
(Empty)
1 // Copyright 2013 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/files/file_path.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chromeos/dbus/fake_dbus_thread_manager.h"
12 #include "chromeos/dbus/fake_debug_daemon_client.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "extensions/common/extension_builder.h"
15 #include "net/dns/mock_host_resolver.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "net/test/embedded_test_server/http_request.h"
18 #include "net/test/embedded_test_server/http_response.h"
19
20 using net::test_server::BasicHttpResponse;
21 using net::test_server::HttpResponse;
22 using net::test_server::HttpRequest;
23
24 namespace {
25
26 const char kFileData[] = "log file content";
27
28 class TestDebugDaemonClient : public chromeos::FakeDebugDaemonClient {
29 public:
30 explicit TestDebugDaemonClient(const base::FilePath& test_file)
31 : test_file_(test_file) {
32 }
33
34 virtual ~TestDebugDaemonClient() {
35 }
36
37 virtual void DumpDebugLogs(bool is_compressed,
38 base::File file,
39 const GetDebugLogsCallback& callback) OVERRIDE {
40 base::File* file_param = new base::File(file.Pass());
41 content::BrowserThread::PostBlockingPoolTaskAndReply(
42 FROM_HERE,
43 base::Bind(&GenerateTestLogDumpFile,
44 test_file_,
45 base::Owned(file_param)),
46 base::Bind(callback, true));
47 }
48
49 static void GenerateTestLogDumpFile(const base::FilePath& test_tar_file,
50 base::File* file) {
51 std::string test_file_content;
52 EXPECT_TRUE(base::ReadFileToString(test_tar_file, &test_file_content))
53 << "Cannot read content of file " << test_tar_file.value();
54 const int data_size = static_cast<int>(test_file_content.size());
55 EXPECT_EQ(data_size, file->Write(0, test_file_content.data(), data_size));
56 EXPECT_TRUE(file->SetLength(data_size));
57 file->Close();
58 }
59
60 private:
61 base::FilePath test_file_;
62 };
63
64 } // namespace
65
66 namespace extensions {
67
68 class LogPrivateApiTest : public ExtensionApiTest {
69 public:
70 LogPrivateApiTest() {}
71
72 virtual ~LogPrivateApiTest() {
73 }
74
75 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
76 chromeos::FakeDBusThreadManager* fake_dbus_thread_manager =
77 new chromeos::FakeDBusThreadManager;
78 fake_dbus_thread_manager->SetFakeClients();
79 base::FilePath tar_file_path =
80 test_data_dir_.Append("log_private/dump_logs/system_logs.tar");
81 fake_dbus_thread_manager->SetDebugDaemonClient(
82 scoped_ptr<chromeos::DebugDaemonClient>(
83 new TestDebugDaemonClient(tar_file_path)));
84 chromeos::DBusThreadManager::SetInstanceForTesting(
85 fake_dbus_thread_manager);
86 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
87 }
88
89 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
90 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse);
91 response->set_code(net::HTTP_OK);
92 response->set_content("<html><head><title>LogPrivateTest</title>"
93 "</head><body>Hello!</body></html>");
94 return response.PassAs<HttpResponse>();
95 }
96 };
97
98 IN_PROC_BROWSER_TEST_F(LogPrivateApiTest, DumpLogsAndCaptureEvents) {
99 // Setup dummy HTTP server.
100 host_resolver()->AddRule("www.test.com", "127.0.0.1");
101 ASSERT_TRUE(StartEmbeddedTestServer());
102 embedded_test_server()->RegisterRequestHandler(
103 base::Bind(&LogPrivateApiTest::HandleRequest, base::Unretained(this)));
104
105 ASSERT_TRUE(RunExtensionTest("log_private/dump_logs"));
106 }
107
108 } // namespace extensions
109
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698