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

Side by Side Diff: chrome/browser/extensions/api/page_capture/page_capture_apitest.cc

Issue 2697833004: Revert of Public Sessions - prompt the user for pageCapture requests (Closed)
Patch Set: Created 3 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h" 7 #include "chrome/browser/extensions/api/page_capture/page_capture_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chromeos/login/login_state.h"
11 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
12 #include "content/public/test/test_utils.h" 11 #include "content/public/test/test_utils.h"
13 #include "extensions/browser/extension_dialog_auto_confirm.h"
14 #include "net/dns/mock_host_resolver.h" 12 #include "net/dns/mock_host_resolver.h"
15 13
16 using extensions::PageCaptureSaveAsMHTMLFunction; 14 using extensions::PageCaptureSaveAsMHTMLFunction;
17 using extensions::ScopedTestDialogAutoConfirm;
18 15
19 class ExtensionPageCaptureApiTest : public ExtensionApiTest { 16 class ExtensionPageCaptureApiTest : public ExtensionApiTest {
20 public: 17 public:
21 void SetUpCommandLine(base::CommandLine* command_line) override { 18 void SetUpCommandLine(base::CommandLine* command_line) override {
22 ExtensionApiTest::SetUpCommandLine(command_line); 19 ExtensionApiTest::SetUpCommandLine(command_line);
23 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); 20 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
24 } 21 }
25 }; 22 };
26 23
27 class PageCaptureSaveAsMHTMLDelegate 24 class PageCaptureSaveAsMHTMLDelegate
(...skipping 12 matching lines...) Expand all
40 } 37 }
41 38
42 base::FilePath temp_file_; 39 base::FilePath temp_file_;
43 }; 40 };
44 41
45 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest, SaveAsMHTML) { 42 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest, SaveAsMHTML) {
46 host_resolver()->AddRule("www.a.com", "127.0.0.1"); 43 host_resolver()->AddRule("www.a.com", "127.0.0.1");
47 ASSERT_TRUE(StartEmbeddedTestServer()); 44 ASSERT_TRUE(StartEmbeddedTestServer());
48 PageCaptureSaveAsMHTMLDelegate delegate; 45 PageCaptureSaveAsMHTMLDelegate delegate;
49 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_; 46 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_;
50 // Make sure the MHTML data gets written to the temporary file.
51 ASSERT_FALSE(delegate.temp_file_.empty()); 47 ASSERT_FALSE(delegate.temp_file_.empty());
52 // Flush the message loops to make sure the delete happens. 48 // Flush the message loops to make sure the delete happens.
53 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); 49 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
54 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); 50 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
55 // Make sure the temporary file is destroyed once the javascript side reads
56 // the contents.
57 ASSERT_FALSE(base::PathExists(delegate.temp_file_)); 51 ASSERT_FALSE(base::PathExists(delegate.temp_file_));
58 } 52 }
59
60 #if defined(OS_CHROMEOS)
61 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest,
62 PublicSessionRequestAllowed) {
63 host_resolver()->AddRule("www.a.com", "127.0.0.1");
64 ASSERT_TRUE(StartEmbeddedTestServer());
65 PageCaptureSaveAsMHTMLDelegate delegate;
66 // Set Public Session state.
67 chromeos::LoginState::Get()->SetLoggedInState(
68 chromeos::LoginState::LOGGED_IN_ACTIVE,
69 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
70 // Resolve Permission dialog with Allow.
71 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::ACCEPT);
72 ASSERT_TRUE(RunExtensionTest("page_capture")) << message_;
73 ASSERT_FALSE(delegate.temp_file_.empty());
74 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
75 content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
76 ASSERT_FALSE(base::PathExists(delegate.temp_file_));
77 }
78
79 IN_PROC_BROWSER_TEST_F(ExtensionPageCaptureApiTest,
80 PublicSessionRequestDenied) {
81 host_resolver()->AddRule("www.a.com", "127.0.0.1");
82 ASSERT_TRUE(StartEmbeddedTestServer());
83 // Set Public Session state.
84 chromeos::LoginState::Get()->SetLoggedInState(
85 chromeos::LoginState::LOGGED_IN_ACTIVE,
86 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
87 // Resolve Permission dialog with Deny.
88 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::CANCEL);
89 ASSERT_TRUE(RunExtensionTestWithArg("page_capture", "REQUEST_DENIED"))
90 << message_;
91 }
92 #endif // defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698