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

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 virtual ~TestDebugDaemonClient() {}
34
35 virtual void DumpDebugLogs(bool is_compressed,
36 base::File file,
37 const GetDebugLogsCallback& callback) OVERRIDE {
38 base::File* file_param = new base::File(file.Pass());
39 content::BrowserThread::PostBlockingPoolTaskAndReply(
40 FROM_HERE,
41 base::Bind(
42 &GenerateTestLogDumpFile, test_file_, base::Owned(file_param)),
43 base::Bind(callback, true));
44 }
45
46 static void GenerateTestLogDumpFile(const base::FilePath& test_tar_file,
47 base::File* file) {
48 std::string test_file_content;
49 EXPECT_TRUE(base::ReadFileToString(test_tar_file, &test_file_content))
50 << "Cannot read content of file " << test_tar_file.value();
51 const int data_size = static_cast<int>(test_file_content.size());
52 EXPECT_EQ(data_size, file->Write(0, test_file_content.data(), data_size));
53 EXPECT_TRUE(file->SetLength(data_size));
54 file->Close();
55 }
56
57 private:
58 base::FilePath test_file_;
59 };
60
61 } // namespace
62
63 namespace extensions {
64
65 class LogPrivateApiTest : public ExtensionApiTest {
66 public:
67 LogPrivateApiTest() {}
68
69 virtual ~LogPrivateApiTest() {}
70
71 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
72 chromeos::FakeDBusThreadManager* fake_dbus_thread_manager =
73 new chromeos::FakeDBusThreadManager;
74 fake_dbus_thread_manager->SetFakeClients();
75 base::FilePath tar_file_path =
76 test_data_dir_.Append("log_private/dump_logs/system_logs.tar");
77 fake_dbus_thread_manager->SetDebugDaemonClient(
78 scoped_ptr<chromeos::DebugDaemonClient>(
79 new TestDebugDaemonClient(tar_file_path)));
80 chromeos::DBusThreadManager::SetInstanceForTesting(
81 fake_dbus_thread_manager);
82 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
83 }
84
85 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) {
86 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse);
87 response->set_code(net::HTTP_OK);
88 response->set_content(
89 "<html><head><title>LogPrivateTest</title>"
90 "</head><body>Hello!</body></html>");
91 return response.PassAs<HttpResponse>();
92 }
93 };
94
95 IN_PROC_BROWSER_TEST_F(LogPrivateApiTest, DumpLogsAndCaptureEvents) {
96 // Setup dummy HTTP server.
97 host_resolver()->AddRule("www.test.com", "127.0.0.1");
98 ASSERT_TRUE(StartEmbeddedTestServer());
99 embedded_test_server()->RegisterRequestHandler(
100 base::Bind(&LogPrivateApiTest::HandleRequest, base::Unretained(this)));
101
102 ASSERT_TRUE(RunExtensionTest("log_private/dump_logs"));
103 }
104
105 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698