Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / apps / web_view_browsertest.cc
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 "apps/ui/native_app_window.h"
6 #include "base/path_service.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/chrome_content_browser_client.h"
12 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/prerender/prerender_link_manager.h"
14 #include "chrome/browser/prerender/prerender_link_manager_factory.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
17 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
18 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_dialogs.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/browser/gpu_data_manager.h"
24 #include "content/public/browser/interstitial_page.h"
25 #include "content/public/browser/interstitial_page_delegate.h"
26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/render_process_host.h"
28 #include "content/public/browser/web_contents_delegate.h"
29 #include "content/public/common/content_switches.h"
30 #include "content/public/test/browser_test_utils.h"
31 #include "content/public/test/fake_speech_recognition_manager.h"
32 #include "extensions/common/extension.h"
33 #include "extensions/common/extensions_client.h"
34 #include "net/test/embedded_test_server/embedded_test_server.h"
35 #include "net/test/embedded_test_server/http_request.h"
36 #include "net/test/embedded_test_server/http_response.h"
37 #include "ui/gl/gl_switches.h"
38
39 #if defined(OS_CHROMEOS)
40 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
41 #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
42 #endif
43
44 // For fine-grained suppression on flaky tests.
45 #if defined(OS_WIN)
46 #include "base/win/windows_version.h"
47 #endif
48
49 using extensions::MenuItem;
50 using prerender::PrerenderLinkManager;
51 using prerender::PrerenderLinkManagerFactory;
52 using task_manager::browsertest_util::MatchAboutBlankTab;
53 using task_manager::browsertest_util::MatchAnyApp;
54 using task_manager::browsertest_util::MatchAnyBackground;
55 using task_manager::browsertest_util::MatchAnyTab;
56 using task_manager::browsertest_util::MatchAnyWebView;
57 using task_manager::browsertest_util::MatchApp;
58 using task_manager::browsertest_util::MatchBackground;
59 using task_manager::browsertest_util::MatchWebView;
60 using task_manager::browsertest_util::WaitForTaskManagerRows;
61 using ui::MenuModel;
62
63 namespace {
64 const char kEmptyResponsePath[] = "/close-socket";
65 const char kRedirectResponsePath[] = "/server-redirect";
66 const char kRedirectResponseFullPath[] =
67     "/extensions/platform_apps/web_view/shim/guest_redirect.html";
68
69 // Platform-specific filename relative to the chrome executable.
70 #if defined(OS_WIN)
71 const wchar_t library_name[] = L"ppapi_tests.dll";
72 #elif defined(OS_MACOSX)
73 const char library_name[] = "ppapi_tests.plugin";
74 #elif defined(OS_POSIX)
75 const char library_name[] = "libppapi_tests.so";
76 #endif
77
78 class EmptyHttpResponse : public net::test_server::HttpResponse {
79  public:
80   virtual std::string ToResponseString() const OVERRIDE {
81     return std::string();
82   }
83 };
84
85 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate {
86  public:
87   TestInterstitialPageDelegate() {
88   }
89   virtual ~TestInterstitialPageDelegate() {}
90   virtual std::string GetHTMLContents() OVERRIDE { return std::string(); }
91 };
92
93 // Used to get notified when a guest is created.
94 class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient {
95  public:
96   GuestContentBrowserClient() : web_contents_(NULL) {}
97
98   content::WebContents* WaitForGuestCreated() {
99     if (web_contents_)
100       return web_contents_;
101
102     message_loop_runner_ = new content::MessageLoopRunner;
103     message_loop_runner_->Run();
104     return web_contents_;
105   }
106
107  private:
108   // ChromeContentBrowserClient implementation:
109   virtual void GuestWebContentsAttached(
110       content::WebContents* guest_web_contents,
111       content::WebContents* embedder_web_contents,
112       const base::DictionaryValue& extra_params) OVERRIDE {
113     ChromeContentBrowserClient::GuestWebContentsAttached(
114         guest_web_contents, embedder_web_contents, extra_params);
115     web_contents_ = guest_web_contents;
116
117     if (message_loop_runner_)
118       message_loop_runner_->Quit();
119   }
120
121   content::WebContents* web_contents_;
122   scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
123 };
124
125 class WebContentsHiddenObserver : public content::WebContentsObserver {
126  public:
127   WebContentsHiddenObserver(content::WebContents* web_contents,
128                             const base::Closure& hidden_callback)
129       : WebContentsObserver(web_contents),
130         hidden_callback_(hidden_callback),
131         hidden_observed_(true) {
132   }
133
134   // WebContentsObserver.
135   virtual void WasHidden() OVERRIDE {
136     hidden_observed_ = true;
137     hidden_callback_.Run();
138   }
139
140   bool hidden_observed() { return hidden_observed_; }
141
142  private:
143   base::Closure hidden_callback_;
144   bool hidden_observed_;
145
146   DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver);
147 };
148
149 class InterstitialObserver : public content::WebContentsObserver {
150  public:
151   InterstitialObserver(content::WebContents* web_contents,
152                        const base::Closure& attach_callback,
153                        const base::Closure& detach_callback)
154       : WebContentsObserver(web_contents),
155         attach_callback_(attach_callback),
156         detach_callback_(detach_callback) {
157   }
158
159   virtual void DidAttachInterstitialPage() OVERRIDE {
160     attach_callback_.Run();
161   }
162
163   virtual void DidDetachInterstitialPage() OVERRIDE {
164     detach_callback_.Run();
165   }
166
167  private:
168   base::Closure attach_callback_;
169   base::Closure detach_callback_;
170
171   DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
172 };
173
174 void ExecuteScriptWaitForTitle(content::WebContents* web_contents,
175                                const char* script,
176                                const char* title) {
177   base::string16 expected_title(base::ASCIIToUTF16(title));
178   base::string16 error_title(base::ASCIIToUTF16("error"));
179
180   content::TitleWatcher title_watcher(web_contents, expected_title);
181   title_watcher.AlsoWaitForTitle(error_title);
182   EXPECT_TRUE(content::ExecuteScript(web_contents, script));
183   EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
184 }
185
186 }  // namespace
187
188 // This class intercepts media access request from the embedder. The request
189 // should be triggered only if the embedder API (from tests) allows the request
190 // in Javascript.
191 // We do not issue the actual media request; the fact that the request reached
192 // embedder's WebContents is good enough for our tests. This is also to make
193 // the test run successfully on trybots.
194 class MockWebContentsDelegate : public content::WebContentsDelegate {
195  public:
196   MockWebContentsDelegate() : requested_(false) {}
197   virtual ~MockWebContentsDelegate() {}
198
199   virtual void RequestMediaAccessPermission(
200       content::WebContents* web_contents,
201       const content::MediaStreamRequest& request,
202       const content::MediaResponseCallback& callback) OVERRIDE {
203     requested_ = true;
204     if (message_loop_runner_.get())
205       message_loop_runner_->Quit();
206   }
207
208   void WaitForSetMediaPermission() {
209     if (requested_)
210       return;
211     message_loop_runner_ = new content::MessageLoopRunner;
212     message_loop_runner_->Run();
213   }
214
215  private:
216   bool requested_;
217   scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
218
219   DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate);
220 };
221
222 // This class intercepts download request from the guest.
223 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate {
224  public:
225   explicit MockDownloadWebContentsDelegate(
226       content::WebContentsDelegate* orig_delegate)
227       : orig_delegate_(orig_delegate),
228         waiting_for_decision_(false),
229         expect_allow_(false),
230         decision_made_(false),
231         last_download_allowed_(false) {}
232   virtual ~MockDownloadWebContentsDelegate() {}
233
234   virtual void CanDownload(
235       content::RenderViewHost* render_view_host,
236       int request_id,
237       const std::string& request_method,
238       const base::Callback<void(bool)>& callback) OVERRIDE {
239     orig_delegate_->CanDownload(
240         render_view_host, request_id, request_method,
241         base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided,
242                    base::Unretained(this)));
243   }
244
245   void WaitForCanDownload(bool expect_allow) {
246     EXPECT_FALSE(waiting_for_decision_);
247     waiting_for_decision_ = true;
248
249     if (decision_made_) {
250       EXPECT_EQ(expect_allow, last_download_allowed_);
251       return;
252     }
253
254     expect_allow_ = expect_allow;
255     message_loop_runner_ = new content::MessageLoopRunner;
256     message_loop_runner_->Run();
257   }
258
259   void DownloadDecided(bool allow) {
260     EXPECT_FALSE(decision_made_);
261     decision_made_ = true;
262
263     if (waiting_for_decision_) {
264       EXPECT_EQ(expect_allow_, allow);
265       if (message_loop_runner_.get())
266         message_loop_runner_->Quit();
267       return;
268     }
269     last_download_allowed_ = allow;
270   }
271
272   void Reset() {
273     waiting_for_decision_ = false;
274     decision_made_ = false;
275   }
276
277  private:
278   content::WebContentsDelegate* orig_delegate_;
279   bool waiting_for_decision_;
280   bool expect_allow_;
281   bool decision_made_;
282   bool last_download_allowed_;
283   scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
284
285   DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate);
286 };
287
288 class WebViewTest : public extensions::PlatformAppBrowserTest {
289  protected:
290   virtual void SetUp() OVERRIDE {
291     if (UsesFakeSpeech()) {
292       // SpeechRecognition test specific SetUp.
293       fake_speech_recognition_manager_.reset(
294           new content::FakeSpeechRecognitionManager());
295       fake_speech_recognition_manager_->set_should_send_fake_response(true);
296       // Inject the fake manager factory so that the test result is returned to
297       // the web page.
298       content::SpeechRecognitionManager::SetManagerForTesting(
299           fake_speech_recognition_manager_.get());
300     }
301     extensions::PlatformAppBrowserTest::SetUp();
302   }
303
304   virtual void TearDown() OVERRIDE {
305     if (UsesFakeSpeech()) {
306       // SpeechRecognition test specific TearDown.
307       content::SpeechRecognitionManager::SetManagerForTesting(NULL);
308     }
309
310     extensions::PlatformAppBrowserTest::TearDown();
311   }
312
313   virtual void SetUpOnMainThread() OVERRIDE {
314     extensions::PlatformAppBrowserTest::SetUpOnMainThread();
315     const testing::TestInfo* const test_info =
316         testing::UnitTest::GetInstance()->current_test_info();
317     // Mock out geolocation for geolocation specific tests.
318     if (!strncmp(test_info->name(), "GeolocationAPI",
319             strlen("GeolocationAPI"))) {
320       ui_test_utils::OverrideGeolocation(10, 20);
321     }
322   }
323
324   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
325     command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
326     command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
327
328     extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
329   }
330
331   // This method is responsible for initializing a packaged app, which contains
332   // multiple webview tags. The tags have different partition identifiers and
333   // their WebContent objects are returned as output. The method also verifies
334   // the expected process allocation and storage partition assignment.
335   // The |navigate_to_url| parameter is used to navigate the main browser
336   // window.
337   //
338   // TODO(ajwong): This function is getting to be too large. Either refactor it
339   // so the test can specify a configuration of WebView tags that we will
340   // dynamically inject JS to generate, or move this test wholesale into
341   // something that RunPlatformAppTest() can execute purely in Javascript. This
342   // won't let us do a white-box examination of the StoragePartition equivalence
343   // directly, but we will be able to view the black box effects which is good
344   // enough.  http://crbug.com/160361
345   void NavigateAndOpenAppForIsolation(
346       GURL navigate_to_url,
347       content::WebContents** default_tag_contents1,
348       content::WebContents** default_tag_contents2,
349       content::WebContents** named_partition_contents1,
350       content::WebContents** named_partition_contents2,
351       content::WebContents** persistent_partition_contents1,
352       content::WebContents** persistent_partition_contents2,
353       content::WebContents** persistent_partition_contents3) {
354     GURL::Replacements replace_host;
355     std::string host_str("localhost");  // Must stay in scope with replace_host.
356     replace_host.SetHostStr(host_str);
357
358     navigate_to_url = navigate_to_url.ReplaceComponents(replace_host);
359
360     GURL tag_url1 = embedded_test_server()->GetURL(
361         "/extensions/platform_apps/web_view/isolation/cookie.html");
362     tag_url1 = tag_url1.ReplaceComponents(replace_host);
363     GURL tag_url2 = embedded_test_server()->GetURL(
364         "/extensions/platform_apps/web_view/isolation/cookie2.html");
365     tag_url2 = tag_url2.ReplaceComponents(replace_host);
366     GURL tag_url3 = embedded_test_server()->GetURL(
367         "/extensions/platform_apps/web_view/isolation/storage1.html");
368     tag_url3 = tag_url3.ReplaceComponents(replace_host);
369     GURL tag_url4 = embedded_test_server()->GetURL(
370         "/extensions/platform_apps/web_view/isolation/storage2.html");
371     tag_url4 = tag_url4.ReplaceComponents(replace_host);
372     GURL tag_url5 = embedded_test_server()->GetURL(
373         "/extensions/platform_apps/web_view/isolation/storage1.html#p1");
374     tag_url5 = tag_url5.ReplaceComponents(replace_host);
375     GURL tag_url6 = embedded_test_server()->GetURL(
376         "/extensions/platform_apps/web_view/isolation/storage1.html#p2");
377     tag_url6 = tag_url6.ReplaceComponents(replace_host);
378     GURL tag_url7 = embedded_test_server()->GetURL(
379         "/extensions/platform_apps/web_view/isolation/storage1.html#p3");
380     tag_url7 = tag_url7.ReplaceComponents(replace_host);
381
382     ui_test_utils::NavigateToURLWithDisposition(
383         browser(), navigate_to_url, CURRENT_TAB,
384         ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
385
386     ui_test_utils::UrlLoadObserver observer1(
387         tag_url1, content::NotificationService::AllSources());
388     ui_test_utils::UrlLoadObserver observer2(
389         tag_url2, content::NotificationService::AllSources());
390     ui_test_utils::UrlLoadObserver observer3(
391         tag_url3, content::NotificationService::AllSources());
392     ui_test_utils::UrlLoadObserver observer4(
393         tag_url4, content::NotificationService::AllSources());
394     ui_test_utils::UrlLoadObserver observer5(
395         tag_url5, content::NotificationService::AllSources());
396     ui_test_utils::UrlLoadObserver observer6(
397         tag_url6, content::NotificationService::AllSources());
398     ui_test_utils::UrlLoadObserver observer7(
399         tag_url7, content::NotificationService::AllSources());
400     LoadAndLaunchPlatformApp("web_view/isolation");
401     observer1.Wait();
402     observer2.Wait();
403     observer3.Wait();
404     observer4.Wait();
405     observer5.Wait();
406     observer6.Wait();
407     observer7.Wait();
408
409     content::Source<content::NavigationController> source1 = observer1.source();
410     EXPECT_TRUE(source1->GetWebContents()->GetRenderProcessHost()->IsGuest());
411     content::Source<content::NavigationController> source2 = observer2.source();
412     EXPECT_TRUE(source2->GetWebContents()->GetRenderProcessHost()->IsGuest());
413     content::Source<content::NavigationController> source3 = observer3.source();
414     EXPECT_TRUE(source3->GetWebContents()->GetRenderProcessHost()->IsGuest());
415     content::Source<content::NavigationController> source4 = observer4.source();
416     EXPECT_TRUE(source4->GetWebContents()->GetRenderProcessHost()->IsGuest());
417     content::Source<content::NavigationController> source5 = observer5.source();
418     EXPECT_TRUE(source5->GetWebContents()->GetRenderProcessHost()->IsGuest());
419     content::Source<content::NavigationController> source6 = observer6.source();
420     EXPECT_TRUE(source6->GetWebContents()->GetRenderProcessHost()->IsGuest());
421     content::Source<content::NavigationController> source7 = observer7.source();
422     EXPECT_TRUE(source7->GetWebContents()->GetRenderProcessHost()->IsGuest());
423
424     // Check that the first two tags use the same process and it is different
425     // than the process used by the other two.
426     EXPECT_EQ(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
427               source2->GetWebContents()->GetRenderProcessHost()->GetID());
428     EXPECT_EQ(source3->GetWebContents()->GetRenderProcessHost()->GetID(),
429               source4->GetWebContents()->GetRenderProcessHost()->GetID());
430     EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
431               source3->GetWebContents()->GetRenderProcessHost()->GetID());
432
433     // The two sets of tags should also be isolated from the main browser.
434     EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
435               browser()->tab_strip_model()->GetWebContentsAt(0)->
436                   GetRenderProcessHost()->GetID());
437     EXPECT_NE(source3->GetWebContents()->GetRenderProcessHost()->GetID(),
438               browser()->tab_strip_model()->GetWebContentsAt(0)->
439                   GetRenderProcessHost()->GetID());
440
441     // Check that the storage partitions of the first two tags match and are
442     // different than the other two.
443     EXPECT_EQ(
444         source1->GetWebContents()->GetRenderProcessHost()->
445             GetStoragePartition(),
446         source2->GetWebContents()->GetRenderProcessHost()->
447             GetStoragePartition());
448     EXPECT_EQ(
449         source3->GetWebContents()->GetRenderProcessHost()->
450             GetStoragePartition(),
451         source4->GetWebContents()->GetRenderProcessHost()->
452             GetStoragePartition());
453     EXPECT_NE(
454         source1->GetWebContents()->GetRenderProcessHost()->
455             GetStoragePartition(),
456         source3->GetWebContents()->GetRenderProcessHost()->
457             GetStoragePartition());
458
459     // Ensure the persistent storage partitions are different.
460     EXPECT_EQ(
461         source5->GetWebContents()->GetRenderProcessHost()->
462             GetStoragePartition(),
463         source6->GetWebContents()->GetRenderProcessHost()->
464             GetStoragePartition());
465     EXPECT_NE(
466         source5->GetWebContents()->GetRenderProcessHost()->
467             GetStoragePartition(),
468         source7->GetWebContents()->GetRenderProcessHost()->
469             GetStoragePartition());
470     EXPECT_NE(
471         source1->GetWebContents()->GetRenderProcessHost()->
472             GetStoragePartition(),
473         source5->GetWebContents()->GetRenderProcessHost()->
474             GetStoragePartition());
475     EXPECT_NE(
476         source1->GetWebContents()->GetRenderProcessHost()->
477             GetStoragePartition(),
478         source7->GetWebContents()->GetRenderProcessHost()->
479             GetStoragePartition());
480
481     *default_tag_contents1 = source1->GetWebContents();
482     *default_tag_contents2 = source2->GetWebContents();
483     *named_partition_contents1 = source3->GetWebContents();
484     *named_partition_contents2 = source4->GetWebContents();
485     if (persistent_partition_contents1) {
486       *persistent_partition_contents1 = source5->GetWebContents();
487     }
488     if (persistent_partition_contents2) {
489       *persistent_partition_contents2 = source6->GetWebContents();
490     }
491     if (persistent_partition_contents3) {
492       *persistent_partition_contents3 = source7->GetWebContents();
493     }
494   }
495
496   // Handles |request| by serving a redirect response.
497   static scoped_ptr<net::test_server::HttpResponse> RedirectResponseHandler(
498       const std::string& path,
499       const GURL& redirect_target,
500       const net::test_server::HttpRequest& request) {
501     if (!StartsWithASCII(path, request.relative_url, true))
502       return scoped_ptr<net::test_server::HttpResponse>();
503
504     scoped_ptr<net::test_server::BasicHttpResponse> http_response(
505         new net::test_server::BasicHttpResponse);
506     http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
507     http_response->AddCustomHeader("Location", redirect_target.spec());
508     return http_response.PassAs<net::test_server::HttpResponse>();
509   }
510
511   // Handles |request| by serving an empty response.
512   static scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler(
513       const std::string& path,
514       const net::test_server::HttpRequest& request) {
515     if (StartsWithASCII(path, request.relative_url, true)) {
516       return scoped_ptr<net::test_server::HttpResponse>(
517           new EmptyHttpResponse);
518     }
519
520     return scoped_ptr<net::test_server::HttpResponse>();
521   }
522
523   // Shortcut to return the current MenuManager.
524   extensions::MenuManager* menu_manager() {
525     return extensions::MenuManager::Get(browser()->profile());
526   }
527
528   // This gets all the items that any extension has registered for possible
529   // inclusion in context menus.
530   MenuItem::List GetItems() {
531     MenuItem::List result;
532     std::set<MenuItem::ExtensionKey> extension_ids =
533         menu_manager()->ExtensionIds();
534     std::set<MenuItem::ExtensionKey>::iterator i;
535     for (i = extension_ids.begin(); i != extension_ids.end(); ++i) {
536       const MenuItem::List* list = menu_manager()->MenuItems(*i);
537       result.insert(result.end(), list->begin(), list->end());
538     }
539     return result;
540   }
541
542   enum TestServer {
543     NEEDS_TEST_SERVER,
544     NO_TEST_SERVER
545   };
546
547   void TestHelper(const std::string& test_name,
548                   const std::string& app_location,
549                   TestServer test_server) {
550     // For serving guest pages.
551     if (test_server == NEEDS_TEST_SERVER) {
552       if (!StartEmbeddedTestServer()) {
553         LOG(ERROR) << "FAILED TO START TEST SERVER.";
554         return;
555       }
556       embedded_test_server()->RegisterRequestHandler(
557           base::Bind(&WebViewTest::RedirectResponseHandler,
558                     kRedirectResponsePath,
559                     embedded_test_server()->GetURL(kRedirectResponseFullPath)));
560
561       embedded_test_server()->RegisterRequestHandler(
562           base::Bind(&WebViewTest::EmptyResponseHandler, kEmptyResponsePath));
563     }
564
565     ExtensionTestMessageListener launched_listener("Launched", false);
566     LoadAndLaunchPlatformApp(app_location.c_str());
567     if (!launched_listener.WaitUntilSatisfied()) {
568       LOG(ERROR) << "TEST DID NOT LAUNCH.";
569       return;
570     }
571
572     // Flush any pending events to make sure we start with a clean slate.
573     content::RunAllPendingInMessageLoop();
574
575     content::WebContents* embedder_web_contents =
576         GetFirstAppWindowWebContents();
577     if (!embedder_web_contents) {
578       LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
579       return;
580     }
581
582     ExtensionTestMessageListener done_listener("TEST_PASSED", false);
583     done_listener.set_failure_message("TEST_FAILED");
584     if (!content::ExecuteScript(
585             embedder_web_contents,
586             base::StringPrintf("runTest('%s')", test_name.c_str()))) {
587       LOG(ERROR) << "UNABLE TO START TEST.";
588       return;
589     }
590     ASSERT_TRUE(done_listener.WaitUntilSatisfied());
591   }
592
593   content::WebContents* LoadGuest(const std::string& guest_path,
594                                   const std::string& app_path) {
595     GURL::Replacements replace_host;
596     std::string host_str("localhost");  // Must stay in scope with replace_host.
597     replace_host.SetHostStr(host_str);
598
599     GURL guest_url = embedded_test_server()->GetURL(guest_path);
600     guest_url = guest_url.ReplaceComponents(replace_host);
601
602     ui_test_utils::UrlLoadObserver guest_observer(
603         guest_url, content::NotificationService::AllSources());
604
605     ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
606     LoadAndLaunchPlatformApp(app_path.c_str());
607     guest_observer.Wait();
608
609     content::Source<content::NavigationController> source =
610         guest_observer.source();
611     EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest());
612
613     bool satisfied = guest_loaded_listener.WaitUntilSatisfied();
614     if (!satisfied)
615       return NULL;
616
617     content::WebContents* guest_web_contents = source->GetWebContents();
618     return guest_web_contents;
619   }
620
621   // Runs media_access/allow tests.
622   void MediaAccessAPIAllowTestHelper(const std::string& test_name);
623
624   // Runs media_access/deny tests, each of them are run separately otherwise
625   // they timeout (mostly on Windows).
626   void MediaAccessAPIDenyTestHelper(const std::string& test_name) {
627     ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
628     ExtensionTestMessageListener loaded_listener("loaded", false);
629     LoadAndLaunchPlatformApp("web_view/media_access/deny");
630     ASSERT_TRUE(loaded_listener.WaitUntilSatisfied());
631
632     content::WebContents* embedder_web_contents =
633         GetFirstAppWindowWebContents();
634     ASSERT_TRUE(embedder_web_contents);
635
636     ExtensionTestMessageListener test_run_listener("PASSED", false);
637     test_run_listener.set_failure_message("FAILED");
638     EXPECT_TRUE(
639         content::ExecuteScript(
640             embedder_web_contents,
641             base::StringPrintf("startDenyTest('%s')", test_name.c_str())));
642     ASSERT_TRUE(test_run_listener.WaitUntilSatisfied());
643   }
644
645   void WaitForInterstitial(content::WebContents* web_contents) {
646     scoped_refptr<content::MessageLoopRunner> loop_runner(
647         new content::MessageLoopRunner);
648     InterstitialObserver observer(web_contents,
649                                   loop_runner->QuitClosure(),
650                                   base::Closure());
651     if (!content::InterstitialPage::GetInterstitialPage(web_contents))
652       loop_runner->Run();
653   }
654
655   void LoadAppWithGuest(const std::string& app_path) {
656     GuestContentBrowserClient new_client;
657     content::ContentBrowserClient* old_client =
658         SetBrowserClientForTesting(&new_client);
659
660     ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED",
661                                                    false);
662     launched_listener.set_failure_message("WebViewTest.FAILURE");
663     LoadAndLaunchPlatformApp(app_path.c_str());
664     ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
665
666     guest_web_contents_ = new_client.WaitForGuestCreated();
667     SetBrowserClientForTesting(old_client);
668   }
669
670   void SendMessageToEmbedder(const std::string& message) {
671     EXPECT_TRUE(
672         content::ExecuteScript(
673             GetEmbedderWebContents(),
674             base::StringPrintf("onAppCommand('%s');", message.c_str())));
675   }
676
677   content::WebContents* GetGuestWebContents() {
678     return guest_web_contents_;
679   }
680
681   content::WebContents* GetEmbedderWebContents() {
682     if (!embedder_web_contents_) {
683       embedder_web_contents_ = GetFirstAppWindowWebContents();
684     }
685     return embedder_web_contents_;
686   }
687
688   WebViewTest() : guest_web_contents_(NULL),
689                   embedder_web_contents_(NULL) {
690   }
691
692  private:
693   bool UsesFakeSpeech() {
694     const testing::TestInfo* const test_info =
695         testing::UnitTest::GetInstance()->current_test_info();
696
697     // SpeechRecognition test specific SetUp.
698     return !strcmp(test_info->name(),
699                    "SpeechRecognitionAPI_HasPermissionAllow");
700   }
701
702   scoped_ptr<content::FakeSpeechRecognitionManager>
703       fake_speech_recognition_manager_;
704
705   // Note that these are only set if you launch app using LoadAppWithGuest().
706   content::WebContents* guest_web_contents_;
707   content::WebContents* embedder_web_contents_;
708 };
709
710 // This test verifies that hiding the guest triggers WebContents::WasHidden().
711 IN_PROC_BROWSER_TEST_F(WebViewTest, GuestVisibilityChanged) {
712   LoadAppWithGuest("web_view/visibility_changed");
713
714   scoped_refptr<content::MessageLoopRunner> loop_runner(
715       new content::MessageLoopRunner);
716   WebContentsHiddenObserver observer(GetGuestWebContents(),
717                                      loop_runner->QuitClosure());
718
719   // Handled in platform_apps/web_view/visibility_changed/main.js
720   SendMessageToEmbedder("hide-guest");
721   if (!observer.hidden_observed())
722     loop_runner->Run();
723 }
724
725 // This test verifies that hiding the embedder also hides the guest.
726 IN_PROC_BROWSER_TEST_F(WebViewTest, EmbedderVisibilityChanged) {
727   LoadAppWithGuest("web_view/visibility_changed");
728
729   scoped_refptr<content::MessageLoopRunner> loop_runner(
730       new content::MessageLoopRunner);
731   WebContentsHiddenObserver observer(GetGuestWebContents(),
732                                      loop_runner->QuitClosure());
733
734   // Handled in platform_apps/web_view/visibility_changed/main.js
735   SendMessageToEmbedder("hide-embedder");
736   if (!observer.hidden_observed())
737     loop_runner->Run();
738 }
739
740 // This test ensures JavaScript errors ("Cannot redefine property") do not
741 // happen when a <webview> is removed from DOM and added back.
742 IN_PROC_BROWSER_TEST_F(WebViewTest,
743                        AddRemoveWebView_AddRemoveWebView) {
744   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
745   ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/addremove"))
746       << message_;
747 }
748
749 IN_PROC_BROWSER_TEST_F(WebViewTest, AutoSize) {
750 #if defined(OS_WIN)
751   // Flaky on XP bot http://crbug.com/299507
752   if (base::win::GetVersion() <= base::win::VERSION_XP)
753     return;
754 #endif
755
756   ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/autosize"))
757       << message_;
758 }
759
760 // http://crbug.com/326332
761 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_Shim_TestAutosizeAfterNavigation) {
762   TestHelper("testAutosizeAfterNavigation", "web_view/shim", NO_TEST_SERVER);
763 }
764
765 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeBeforeNavigation) {
766   TestHelper("testAutosizeBeforeNavigation", "web_view/shim", NO_TEST_SERVER);
767 }
768 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAutosizeRemoveAttributes) {
769   TestHelper("testAutosizeRemoveAttributes", "web_view/shim", NO_TEST_SERVER);
770 }
771
772 // This test is disabled due to being flaky. http://crbug.com/282116
773 #if defined(OS_WIN)
774 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
775     DISABLED_Shim_TestAutosizeWithPartialAttributes
776 #else
777 #define MAYBE_Shim_TestAutosizeWithPartialAttributes \
778     Shim_TestAutosizeWithPartialAttributes
779 #endif
780 IN_PROC_BROWSER_TEST_F(WebViewTest,
781                        MAYBE_Shim_TestAutosizeWithPartialAttributes) {
782   TestHelper("testAutosizeWithPartialAttributes",
783              "web_view/shim",
784              NO_TEST_SERVER);
785 }
786
787 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAPIMethodExistence) {
788   TestHelper("testAPIMethodExistence", "web_view/shim", NO_TEST_SERVER);
789 }
790
791 // Tests the existence of WebRequest API event objects on the request
792 // object, on the webview element, and hanging directly off webview.
793 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIExistence) {
794   TestHelper("testWebRequestAPIExistence", "web_view/shim", NO_TEST_SERVER);
795 }
796
797 // http://crbug.com/315920
798 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
799 #define MAYBE_Shim_TestChromeExtensionURL DISABLED_Shim_TestChromeExtensionURL
800 #else
801 #define MAYBE_Shim_TestChromeExtensionURL Shim_TestChromeExtensionURL
802 #endif
803 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_Shim_TestChromeExtensionURL) {
804   TestHelper("testChromeExtensionURL", "web_view/shim", NO_TEST_SERVER);
805 }
806
807 // http://crbug.com/315920
808 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
809 #define MAYBE_Shim_TestChromeExtensionRelativePath \
810     DISABLED_Shim_TestChromeExtensionRelativePath
811 #else
812 #define MAYBE_Shim_TestChromeExtensionRelativePath \
813     Shim_TestChromeExtensionRelativePath
814 #endif
815 IN_PROC_BROWSER_TEST_F(WebViewTest,
816                        MAYBE_Shim_TestChromeExtensionRelativePath) {
817   TestHelper("testChromeExtensionRelativePath",
818              "web_view/shim",
819              NO_TEST_SERVER);
820 }
821
822 IN_PROC_BROWSER_TEST_F(WebViewTest,
823                        Shim_TestInlineScriptFromAccessibleResources) {
824   TestHelper("testInlineScriptFromAccessibleResources",
825              "web_view/shim",
826              NO_TEST_SERVER);
827 }
828
829 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestInvalidChromeExtensionURL) {
830   TestHelper("testInvalidChromeExtensionURL", "web_view/shim", NO_TEST_SERVER);
831 }
832
833 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestEventName) {
834   TestHelper("testEventName", "web_view/shim", NO_TEST_SERVER);
835 }
836
837 // WebViewTest.Shim_TestOnEventProperty is flaky, so disable it.
838 // http://crbug.com/359832.
839 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_Shim_TestOnEventProperty) {
840   TestHelper("testOnEventProperties", "web_view/shim", NO_TEST_SERVER);
841 }
842
843 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadProgressEvent) {
844   TestHelper("testLoadProgressEvent", "web_view/shim", NO_TEST_SERVER);
845 }
846
847 // WebViewTest.Shim_TestDestroyOnEventListener is flaky, so disable it.
848 // http://crbug.com/255106
849 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_Shim_TestDestroyOnEventListener) {
850   TestHelper("testDestroyOnEventListener", "web_view/shim", NO_TEST_SERVER);
851 }
852
853 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestCannotMutateEventName) {
854   TestHelper("testCannotMutateEventName", "web_view/shim", NO_TEST_SERVER);
855 }
856
857 // http://crbug.com/267304
858 #if defined(OS_WIN)
859 #define MAYBE_Shim_TestPartitionRaisesException \
860   DISABLED_Shim_TestPartitionRaisesException
861 #else
862 #define MAYBE_Shim_TestPartitionRaisesException \
863   Shim_TestPartitionRaisesException
864 #endif
865
866 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_Shim_TestPartitionRaisesException) {
867   TestHelper("testPartitionRaisesException",
868              "web_view/shim",
869              NO_TEST_SERVER);
870 }
871
872 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScriptFail) {
873 #if defined(OS_WIN)
874   // Flaky on XP bot http://crbug.com/266185
875   if (base::win::GetVersion() <= base::win::VERSION_XP)
876     return;
877 #endif
878
879   TestHelper("testExecuteScriptFail", "web_view/shim", NEEDS_TEST_SERVER);
880 }
881
882 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestExecuteScript) {
883   TestHelper("testExecuteScript", "web_view/shim", NO_TEST_SERVER);
884 }
885
886 IN_PROC_BROWSER_TEST_F(
887     WebViewTest,
888     Shim_TestExecuteScriptIsAbortedWhenWebViewSourceIsChanged) {
889   TestHelper("testExecuteScriptIsAbortedWhenWebViewSourceIsChanged",
890              "web_view/shim",
891              NO_TEST_SERVER);
892 }
893
894 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestTerminateAfterExit) {
895   TestHelper("testTerminateAfterExit", "web_view/shim", NO_TEST_SERVER);
896 }
897
898 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestAssignSrcAfterCrash) {
899   TestHelper("testAssignSrcAfterCrash", "web_view/shim", NO_TEST_SERVER);
900 }
901
902 IN_PROC_BROWSER_TEST_F(WebViewTest,
903                        Shim_TestNavOnConsecutiveSrcAttributeChanges) {
904   TestHelper("testNavOnConsecutiveSrcAttributeChanges",
905              "web_view/shim",
906              NO_TEST_SERVER);
907 }
908
909 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavOnSrcAttributeChange) {
910   TestHelper("testNavOnSrcAttributeChange", "web_view/shim", NO_TEST_SERVER);
911 }
912
913 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveSrcAttribute) {
914   TestHelper("testRemoveSrcAttribute", "web_view/shim", NO_TEST_SERVER);
915 }
916
917 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReassignSrcAttribute) {
918   TestHelper("testReassignSrcAttribute", "web_view/shim", NO_TEST_SERVER);
919 }
920
921 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestBrowserPluginNotAllowed) {
922 #if defined(OS_WIN)
923   // Flaky on XP bots. http://crbug.com/267300
924   if (base::win::GetVersion() <= base::win::VERSION_XP)
925     return;
926 #endif
927
928   TestHelper("testBrowserPluginNotAllowed", "web_view/shim", NO_TEST_SERVER);
929 }
930
931 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindow) {
932   TestHelper("testNewWindow", "web_view/shim", NEEDS_TEST_SERVER);
933 }
934
935 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowTwoListeners) {
936   TestHelper("testNewWindowTwoListeners", "web_view/shim", NEEDS_TEST_SERVER);
937 }
938
939 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowNoPreventDefault) {
940   TestHelper("testNewWindowNoPreventDefault",
941              "web_view/shim",
942              NEEDS_TEST_SERVER);
943 }
944
945 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNewWindowNoReferrerLink) {
946   TestHelper("testNewWindowNoReferrerLink", "web_view/shim", NEEDS_TEST_SERVER);
947 }
948
949 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestContentLoadEvent) {
950   TestHelper("testContentLoadEvent", "web_view/shim", NO_TEST_SERVER);
951 }
952
953 // http://crbug.com/326330
954 IN_PROC_BROWSER_TEST_F(WebViewTest,
955                        DISABLED_Shim_TestDeclarativeWebRequestAPI) {
956   TestHelper("testDeclarativeWebRequestAPI",
957              "web_view/shim",
958              NEEDS_TEST_SERVER);
959 }
960
961 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPI) {
962   TestHelper("testWebRequestAPI", "web_view/shim", NEEDS_TEST_SERVER);
963 }
964
965 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestWebRequestAPIGoogleProperty) {
966   TestHelper("testWebRequestAPIGoogleProperty",
967              "web_view/shim",
968              NO_TEST_SERVER);
969 }
970
971 // This test is disabled due to being flaky. http://crbug.com/309451
972 #if defined(OS_WIN)
973 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
974     DISABLED_Shim_TestWebRequestListenerSurvivesReparenting
975 #else
976 #define MAYBE_Shim_TestWebRequestListenerSurvivesReparenting \
977     Shim_TestWebRequestListenerSurvivesReparenting
978 #endif
979 IN_PROC_BROWSER_TEST_F(
980     WebViewTest,
981     MAYBE_Shim_TestWebRequestListenerSurvivesReparenting) {
982   TestHelper("testWebRequestListenerSurvivesReparenting",
983              "web_view/shim",
984              NEEDS_TEST_SERVER);
985 }
986
987 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadStartLoadRedirect) {
988   TestHelper("testLoadStartLoadRedirect", "web_view/shim", NEEDS_TEST_SERVER);
989 }
990
991 IN_PROC_BROWSER_TEST_F(WebViewTest,
992                        Shim_TestLoadAbortChromeExtensionURLWrongPartition) {
993   TestHelper("testLoadAbortChromeExtensionURLWrongPartition",
994              "web_view/shim",
995              NO_TEST_SERVER);
996 }
997
998 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortEmptyResponse) {
999   TestHelper("testLoadAbortEmptyResponse", "web_view/shim", NEEDS_TEST_SERVER);
1000 }
1001
1002 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalChromeURL) {
1003   TestHelper("testLoadAbortIllegalChromeURL",
1004              "web_view/shim",
1005              NO_TEST_SERVER);
1006 }
1007
1008 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalFileURL) {
1009   TestHelper("testLoadAbortIllegalFileURL", "web_view/shim", NO_TEST_SERVER);
1010 }
1011
1012 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestLoadAbortIllegalJavaScriptURL) {
1013   TestHelper("testLoadAbortIllegalJavaScriptURL",
1014              "web_view/shim",
1015              NO_TEST_SERVER);
1016 }
1017
1018 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestReload) {
1019   TestHelper("testReload", "web_view/shim", NEEDS_TEST_SERVER);
1020 }
1021
1022 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGetProcessId) {
1023   TestHelper("testGetProcessId", "web_view/shim", NEEDS_TEST_SERVER);
1024 }
1025
1026 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewOnExit) {
1027   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
1028
1029   // Launch the app and wait until it's ready to load a test.
1030   ExtensionTestMessageListener launched_listener("Launched", false);
1031   LoadAndLaunchPlatformApp("web_view/shim");
1032   ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
1033
1034   content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1035   ASSERT_TRUE(embedder_web_contents);
1036
1037   GURL::Replacements replace_host;
1038   std::string host_str("localhost");  // Must stay in scope with replace_host.
1039   replace_host.SetHostStr(host_str);
1040
1041   std::string guest_path(
1042       "/extensions/platform_apps/web_view/shim/empty_guest.html");
1043   GURL guest_url = embedded_test_server()->GetURL(guest_path);
1044   guest_url = guest_url.ReplaceComponents(replace_host);
1045
1046   ui_test_utils::UrlLoadObserver guest_observer(
1047       guest_url, content::NotificationService::AllSources());
1048
1049   // Run the test and wait until the guest WebContents is available and has
1050   // finished loading.
1051   ExtensionTestMessageListener guest_loaded_listener("guest-loaded", false);
1052   EXPECT_TRUE(content::ExecuteScript(
1053                   embedder_web_contents,
1054                   "runTest('testRemoveWebviewOnExit')"));
1055   guest_observer.Wait();
1056
1057   content::Source<content::NavigationController> source =
1058       guest_observer.source();
1059   EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest());
1060
1061   ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied());
1062
1063   content::WebContentsDestroyedWatcher destroyed_watcher(
1064       source->GetWebContents());
1065
1066   // Tell the embedder to kill the guest.
1067   EXPECT_TRUE(content::ExecuteScript(
1068                   embedder_web_contents,
1069                   "removeWebviewOnExitDoCrash();"));
1070
1071   // Wait until the guest WebContents is destroyed.
1072   destroyed_watcher.Wait();
1073 }
1074
1075 // Remove <webview> immediately after navigating it.
1076 // This is a regression test for http://crbug.com/276023.
1077 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestRemoveWebviewAfterNavigation) {
1078   TestHelper("testRemoveWebviewAfterNavigation",
1079              "web_view/shim",
1080              NO_TEST_SERVER);
1081 }
1082
1083 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestNavigationToExternalProtocol) {
1084   TestHelper("testNavigationToExternalProtocol",
1085              "web_view/shim",
1086              NO_TEST_SERVER);
1087 }
1088
1089 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestResizeWebviewResizesContent) {
1090   TestHelper("testResizeWebviewResizesContent",
1091              "web_view/shim",
1092              NO_TEST_SERVER);
1093 }
1094
1095 // This test makes sure we do not crash if app is closed while interstitial
1096 // page is being shown in guest.
1097 // Disabled under LeakSanitizer due to memory leaks. http://crbug.com/321662
1098 #if defined(LEAK_SANITIZER)
1099 #define MAYBE_InterstitialTeardown DISABLED_InterstitialTeardown
1100 #else
1101 #define MAYBE_InterstitialTeardown InterstitialTeardown
1102 #endif
1103 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_InterstitialTeardown) {
1104 #if defined(OS_WIN)
1105   // Flaky on XP bot http://crbug.com/297014
1106   if (base::win::GetVersion() <= base::win::VERSION_XP)
1107     return;
1108 #endif
1109
1110   // Start a HTTPS server so we can load an interstitial page inside guest.
1111   net::SpawnedTestServer::SSLOptions ssl_options;
1112   ssl_options.server_certificate =
1113       net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME;
1114   net::SpawnedTestServer https_server(
1115       net::SpawnedTestServer::TYPE_HTTPS, ssl_options,
1116       base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
1117   ASSERT_TRUE(https_server.Start());
1118
1119   net::HostPortPair host_and_port = https_server.host_port_pair();
1120
1121   ExtensionTestMessageListener embedder_loaded_listener("EmbedderLoaded",
1122                                                         false);
1123   LoadAndLaunchPlatformApp("web_view/interstitial_teardown");
1124   ASSERT_TRUE(embedder_loaded_listener.WaitUntilSatisfied());
1125
1126   GuestContentBrowserClient new_client;
1127   content::ContentBrowserClient* old_client =
1128       SetBrowserClientForTesting(&new_client);
1129
1130   // Now load the guest.
1131   content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1132   ExtensionTestMessageListener second("GuestAddedToDom", false);
1133   EXPECT_TRUE(content::ExecuteScript(
1134       embedder_web_contents,
1135       base::StringPrintf("loadGuest(%d);\n", host_and_port.port())));
1136   ASSERT_TRUE(second.WaitUntilSatisfied());
1137
1138   // Wait for interstitial page to be shown in guest.
1139   content::WebContents* guest_web_contents = new_client.WaitForGuestCreated();
1140   SetBrowserClientForTesting(old_client);
1141   ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsGuest());
1142   WaitForInterstitial(guest_web_contents);
1143
1144   // Now close the app while interstitial page being shown in guest.
1145   apps::AppWindow* window = GetFirstAppWindow();
1146   window->GetBaseWindow()->Close();
1147 }
1148
1149 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) {
1150   ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/src_attribute"))
1151       << message_;
1152 }
1153
1154 // This test verifies that prerendering has been disabled inside <webview>.
1155 // This test is here rather than in PrerenderBrowserTest for testing convenience
1156 // only. If it breaks then this is a bug in the prerenderer.
1157 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPrerenderer) {
1158   ASSERT_TRUE(StartEmbeddedTestServer());
1159   content::WebContents* guest_web_contents =
1160       LoadGuest(
1161           "/extensions/platform_apps/web_view/noprerenderer/guest.html",
1162           "web_view/noprerenderer");
1163   ASSERT_TRUE(guest_web_contents != NULL);
1164
1165   PrerenderLinkManager* prerender_link_manager =
1166       PrerenderLinkManagerFactory::GetForProfile(
1167           Profile::FromBrowserContext(guest_web_contents->GetBrowserContext()));
1168   ASSERT_TRUE(prerender_link_manager != NULL);
1169   EXPECT_TRUE(prerender_link_manager->IsEmpty());
1170 }
1171
1172 // Verify that existing <webview>'s are detected when the task manager starts
1173 // up.
1174 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerExistingWebView) {
1175   ASSERT_TRUE(StartEmbeddedTestServer());
1176
1177   LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1178             "web_view/task_manager");
1179
1180   chrome::ShowTaskManager(browser());  // Show task manager AFTER guest loads.
1181
1182   const char* guest_title = "WebViewed test content";
1183   const char* app_name = "<webview> task manager test";
1184   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title)));
1185   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1186   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name)));
1187   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name)));
1188
1189   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1190   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1191   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1192   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1193 }
1194
1195 // Verify that the task manager notices the creation of new <webview>'s.
1196 IN_PROC_BROWSER_TEST_F(WebViewTest, TaskManagerNewWebView) {
1197   ASSERT_TRUE(StartEmbeddedTestServer());
1198
1199   chrome::ShowTaskManager(browser());  // Show task manager BEFORE guest loads.
1200
1201   LoadGuest("/extensions/platform_apps/web_view/task_manager/guest.html",
1202             "web_view/task_manager");
1203
1204   const char* guest_title = "WebViewed test content";
1205   const char* app_name = "<webview> task manager test";
1206   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchWebView(guest_title)));
1207   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAboutBlankTab()));
1208   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchApp(app_name)));
1209   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchBackground(app_name)));
1210
1211   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyWebView()));
1212   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyTab()));
1213   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyApp()));
1214   ASSERT_NO_FATAL_FAILURE(WaitForTaskManagerRows(1, MatchAnyBackground()));
1215 }
1216
1217 // This tests cookie isolation for packaged apps with webview tags. It navigates
1218 // the main browser window to a page that sets a cookie and loads an app with
1219 // multiple webview tags. Each tag sets a cookie and the test checks the proper
1220 // storage isolation is enforced.
1221 // This test is disabled due to being flaky. http://crbug.com/294196
1222 #if defined(OS_WIN)
1223 #define MAYBE_CookieIsolation DISABLED_CookieIsolation
1224 #else
1225 #define MAYBE_CookieIsolation CookieIsolation
1226 #endif
1227 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_CookieIsolation) {
1228   ASSERT_TRUE(StartEmbeddedTestServer());
1229   const std::string kExpire =
1230       "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1231   std::string cookie_script1(kExpire);
1232   cookie_script1.append(
1233       "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';");
1234   std::string cookie_script2(kExpire);
1235   cookie_script2.append(
1236       "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';");
1237
1238   GURL::Replacements replace_host;
1239   std::string host_str("localhost");  // Must stay in scope with replace_host.
1240   replace_host.SetHostStr(host_str);
1241
1242   GURL set_cookie_url = embedded_test_server()->GetURL(
1243       "/extensions/platform_apps/isolation/set_cookie.html");
1244   set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
1245
1246   // The first two partitions will be used to set cookies and ensure they are
1247   // shared. The named partition is used to ensure that cookies are isolated
1248   // between partitions within the same app.
1249   content::WebContents* cookie_contents1;
1250   content::WebContents* cookie_contents2;
1251   content::WebContents* named_partition_contents1;
1252   content::WebContents* named_partition_contents2;
1253
1254   NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1,
1255                                  &cookie_contents2, &named_partition_contents1,
1256                                  &named_partition_contents2, NULL, NULL, NULL);
1257
1258   EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1));
1259   EXPECT_TRUE(content::ExecuteScript(cookie_contents2, cookie_script2));
1260
1261   int cookie_size;
1262   std::string cookie_value;
1263
1264   // Test the regular browser context to ensure we have only one cookie.
1265   ui_test_utils::GetCookies(GURL("http://localhost"),
1266                             browser()->tab_strip_model()->GetWebContentsAt(0),
1267                             &cookie_size, &cookie_value);
1268   EXPECT_EQ("testCookie=1", cookie_value);
1269
1270   // The default behavior is to combine webview tags with no explicit partition
1271   // declaration into the same in-memory partition. Test the webview tags to
1272   // ensure we have properly set the cookies and we have both cookies in both
1273   // tags.
1274   ui_test_utils::GetCookies(GURL("http://localhost"),
1275                             cookie_contents1,
1276                             &cookie_size, &cookie_value);
1277   EXPECT_EQ("guest1=true; guest2=true", cookie_value);
1278
1279   ui_test_utils::GetCookies(GURL("http://localhost"),
1280                             cookie_contents2,
1281                             &cookie_size, &cookie_value);
1282   EXPECT_EQ("guest1=true; guest2=true", cookie_value);
1283
1284   // The third tag should not have any cookies as it is in a separate partition.
1285   ui_test_utils::GetCookies(GURL("http://localhost"),
1286                             named_partition_contents1,
1287                             &cookie_size, &cookie_value);
1288   EXPECT_EQ("", cookie_value);
1289 }
1290
1291 // This tests that in-memory storage partitions are reset on browser restart,
1292 // but persistent ones maintain state for cookies and HTML5 storage.
1293 IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) {
1294   ASSERT_TRUE(StartEmbeddedTestServer());
1295   const std::string kExpire =
1296       "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
1297   std::string cookie_script1(kExpire);
1298   cookie_script1.append(
1299       "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';");
1300   std::string cookie_script2(kExpire);
1301   cookie_script2.append(
1302       "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
1303   std::string cookie_script3(kExpire);
1304   cookie_script3.append(
1305       "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
1306
1307   // We don't care where the main browser is on this test.
1308   GURL blank_url("about:blank");
1309
1310   // The first two partitions will be used to set cookies and ensure they are
1311   // shared. The named partition is used to ensure that cookies are isolated
1312   // between partitions within the same app.
1313   content::WebContents* cookie_contents1;
1314   content::WebContents* cookie_contents2;
1315   content::WebContents* named_partition_contents1;
1316   content::WebContents* named_partition_contents2;
1317   content::WebContents* persistent_partition_contents1;
1318   content::WebContents* persistent_partition_contents2;
1319   content::WebContents* persistent_partition_contents3;
1320   NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
1321                                  &cookie_contents2, &named_partition_contents1,
1322                                  &named_partition_contents2,
1323                                  &persistent_partition_contents1,
1324                                  &persistent_partition_contents2,
1325                                  &persistent_partition_contents3);
1326
1327   // Set the inmemory=true cookie for tags with inmemory partitions.
1328   EXPECT_TRUE(content::ExecuteScript(cookie_contents1, cookie_script1));
1329   EXPECT_TRUE(content::ExecuteScript(named_partition_contents1,
1330                                      cookie_script1));
1331
1332   // For the two different persistent storage partitions, set the
1333   // two different cookies so we can check that they aren't comingled below.
1334   EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents1,
1335                                      cookie_script2));
1336
1337   EXPECT_TRUE(content::ExecuteScript(persistent_partition_contents3,
1338                                      cookie_script3));
1339
1340   int cookie_size;
1341   std::string cookie_value;
1342
1343   // Check that all in-memory partitions have a cookie set.
1344   ui_test_utils::GetCookies(GURL("http://localhost"),
1345                             cookie_contents1,
1346                             &cookie_size, &cookie_value);
1347   EXPECT_EQ("inmemory=true", cookie_value);
1348   ui_test_utils::GetCookies(GURL("http://localhost"),
1349                             cookie_contents2,
1350                             &cookie_size, &cookie_value);
1351   EXPECT_EQ("inmemory=true", cookie_value);
1352   ui_test_utils::GetCookies(GURL("http://localhost"),
1353                             named_partition_contents1,
1354                             &cookie_size, &cookie_value);
1355   EXPECT_EQ("inmemory=true", cookie_value);
1356   ui_test_utils::GetCookies(GURL("http://localhost"),
1357                             named_partition_contents2,
1358                             &cookie_size, &cookie_value);
1359   EXPECT_EQ("inmemory=true", cookie_value);
1360
1361   // Check that all persistent partitions kept their state.
1362   ui_test_utils::GetCookies(GURL("http://localhost"),
1363                             persistent_partition_contents1,
1364                             &cookie_size, &cookie_value);
1365   EXPECT_EQ("persist1=true", cookie_value);
1366   ui_test_utils::GetCookies(GURL("http://localhost"),
1367                             persistent_partition_contents2,
1368                             &cookie_size, &cookie_value);
1369   EXPECT_EQ("persist1=true", cookie_value);
1370   ui_test_utils::GetCookies(GURL("http://localhost"),
1371                             persistent_partition_contents3,
1372                             &cookie_size, &cookie_value);
1373   EXPECT_EQ("persist2=true", cookie_value);
1374 }
1375
1376 // This is the post-reset portion of the StoragePersistence test.  See
1377 // PRE_StoragePersistence for main comment.
1378 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_StoragePersistence) {
1379   ASSERT_TRUE(StartEmbeddedTestServer());
1380
1381   // We don't care where the main browser is on this test.
1382   GURL blank_url("about:blank");
1383
1384   // The first two partitions will be used to set cookies and ensure they are
1385   // shared. The named partition is used to ensure that cookies are isolated
1386   // between partitions within the same app.
1387   content::WebContents* cookie_contents1;
1388   content::WebContents* cookie_contents2;
1389   content::WebContents* named_partition_contents1;
1390   content::WebContents* named_partition_contents2;
1391   content::WebContents* persistent_partition_contents1;
1392   content::WebContents* persistent_partition_contents2;
1393   content::WebContents* persistent_partition_contents3;
1394   NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
1395                                  &cookie_contents2, &named_partition_contents1,
1396                                  &named_partition_contents2,
1397                                  &persistent_partition_contents1,
1398                                  &persistent_partition_contents2,
1399                                  &persistent_partition_contents3);
1400
1401   int cookie_size;
1402   std::string cookie_value;
1403
1404   // Check that all in-memory partitions lost their state.
1405   ui_test_utils::GetCookies(GURL("http://localhost"),
1406                             cookie_contents1,
1407                             &cookie_size, &cookie_value);
1408   EXPECT_EQ("", cookie_value);
1409   ui_test_utils::GetCookies(GURL("http://localhost"),
1410                             cookie_contents2,
1411                             &cookie_size, &cookie_value);
1412   EXPECT_EQ("", cookie_value);
1413   ui_test_utils::GetCookies(GURL("http://localhost"),
1414                             named_partition_contents1,
1415                             &cookie_size, &cookie_value);
1416   EXPECT_EQ("", cookie_value);
1417   ui_test_utils::GetCookies(GURL("http://localhost"),
1418                             named_partition_contents2,
1419                             &cookie_size, &cookie_value);
1420   EXPECT_EQ("", cookie_value);
1421
1422   // Check that all persistent partitions kept their state.
1423   ui_test_utils::GetCookies(GURL("http://localhost"),
1424                             persistent_partition_contents1,
1425                             &cookie_size, &cookie_value);
1426   EXPECT_EQ("persist1=true", cookie_value);
1427   ui_test_utils::GetCookies(GURL("http://localhost"),
1428                             persistent_partition_contents2,
1429                             &cookie_size, &cookie_value);
1430   EXPECT_EQ("persist1=true", cookie_value);
1431   ui_test_utils::GetCookies(GURL("http://localhost"),
1432                             persistent_partition_contents3,
1433                             &cookie_size, &cookie_value);
1434   EXPECT_EQ("persist2=true", cookie_value);
1435 }
1436
1437 #if defined(OS_WIN)
1438 // This test is very flaky on Win Aura, Win XP, Win 7. http://crbug.com/248873
1439 #define MAYBE_DOMStorageIsolation DISABLED_DOMStorageIsolation
1440 #else
1441 #define MAYBE_DOMStorageIsolation DOMStorageIsolation
1442 #endif
1443
1444 // This tests DOM storage isolation for packaged apps with webview tags. It
1445 // loads an app with multiple webview tags and each tag sets DOM storage
1446 // entries, which the test checks to ensure proper storage isolation is
1447 // enforced.
1448 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_DOMStorageIsolation) {
1449   ASSERT_TRUE(StartEmbeddedTestServer());
1450   GURL regular_url = embedded_test_server()->GetURL("/title1.html");
1451
1452   std::string output;
1453   std::string get_local_storage("window.domAutomationController.send("
1454       "window.localStorage.getItem('foo') || 'badval')");
1455   std::string get_session_storage("window.domAutomationController.send("
1456       "window.sessionStorage.getItem('bar') || 'badval')");
1457
1458   content::WebContents* default_tag_contents1;
1459   content::WebContents* default_tag_contents2;
1460   content::WebContents* storage_contents1;
1461   content::WebContents* storage_contents2;
1462
1463   NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
1464                                  &default_tag_contents2, &storage_contents1,
1465                                  &storage_contents2, NULL, NULL, NULL);
1466
1467   // Initialize the storage for the first of the two tags that share a storage
1468   // partition.
1469   EXPECT_TRUE(content::ExecuteScript(storage_contents1,
1470                                      "initDomStorage('page1')"));
1471
1472   // Let's test that the expected values are present in the first tag, as they
1473   // will be overwritten once we call the initDomStorage on the second tag.
1474   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1475                                             get_local_storage.c_str(),
1476                                             &output));
1477   EXPECT_STREQ("local-page1", output.c_str());
1478   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1479                                             get_session_storage.c_str(),
1480                                             &output));
1481   EXPECT_STREQ("session-page1", output.c_str());
1482
1483   // Now, init the storage in the second tag in the same storage partition,
1484   // which will overwrite the shared localStorage.
1485   EXPECT_TRUE(content::ExecuteScript(storage_contents2,
1486                                      "initDomStorage('page2')"));
1487
1488   // The localStorage value now should reflect the one written through the
1489   // second tag.
1490   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1491                                             get_local_storage.c_str(),
1492                                             &output));
1493   EXPECT_STREQ("local-page2", output.c_str());
1494   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1495                                             get_local_storage.c_str(),
1496                                             &output));
1497   EXPECT_STREQ("local-page2", output.c_str());
1498
1499   // Session storage is not shared though, as each webview tag has separate
1500   // instance, even if they are in the same storage partition.
1501   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1502                                             get_session_storage.c_str(),
1503                                             &output));
1504   EXPECT_STREQ("session-page1", output.c_str());
1505   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1506                                             get_session_storage.c_str(),
1507                                             &output));
1508   EXPECT_STREQ("session-page2", output.c_str());
1509
1510   // Also, let's check that the main browser and another tag that doesn't share
1511   // the same partition don't have those values stored.
1512   EXPECT_TRUE(ExecuteScriptAndExtractString(
1513       browser()->tab_strip_model()->GetWebContentsAt(0),
1514       get_local_storage.c_str(),
1515       &output));
1516   EXPECT_STREQ("badval", output.c_str());
1517   EXPECT_TRUE(ExecuteScriptAndExtractString(
1518       browser()->tab_strip_model()->GetWebContentsAt(0),
1519       get_session_storage.c_str(),
1520       &output));
1521   EXPECT_STREQ("badval", output.c_str());
1522   EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1,
1523                                             get_local_storage.c_str(),
1524                                             &output));
1525   EXPECT_STREQ("badval", output.c_str());
1526   EXPECT_TRUE(ExecuteScriptAndExtractString(default_tag_contents1,
1527                                             get_session_storage.c_str(),
1528                                             &output));
1529   EXPECT_STREQ("badval", output.c_str());
1530 }
1531
1532 // See crbug.com/248500
1533 #if defined(OS_WIN)
1534 #define MAYBE_IndexedDBIsolation DISABLED_IndexedDBIsolation
1535 #else
1536 #define MAYBE_IndexedDBIsolation IndexedDBIsolation
1537 #endif
1538
1539 // This tests IndexedDB isolation for packaged apps with webview tags. It loads
1540 // an app with multiple webview tags and each tag creates an IndexedDB record,
1541 // which the test checks to ensure proper storage isolation is enforced.
1542 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_IndexedDBIsolation) {
1543   ASSERT_TRUE(StartEmbeddedTestServer());
1544   GURL regular_url = embedded_test_server()->GetURL("/title1.html");
1545
1546   content::WebContents* default_tag_contents1;
1547   content::WebContents* default_tag_contents2;
1548   content::WebContents* storage_contents1;
1549   content::WebContents* storage_contents2;
1550
1551   NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
1552                                  &default_tag_contents2, &storage_contents1,
1553                                  &storage_contents2, NULL, NULL, NULL);
1554
1555   // Initialize the storage for the first of the two tags that share a storage
1556   // partition.
1557   ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created");
1558   ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')",
1559                             "addItemIDB complete");
1560   ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
1561                             "readItemIDB complete");
1562
1563   std::string output;
1564   std::string get_value(
1565       "window.domAutomationController.send(getValueIDB() || 'badval')");
1566
1567   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1568                                             get_value.c_str(), &output));
1569   EXPECT_STREQ("page1", output.c_str());
1570
1571   // Initialize the db in the second tag.
1572   ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open");
1573
1574   // Since we share a partition, reading the value should return the existing
1575   // one.
1576   ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
1577                             "readItemIDB complete");
1578   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1579                                             get_value.c_str(), &output));
1580   EXPECT_STREQ("page1", output.c_str());
1581
1582   // Now write through the second tag and read it back.
1583   ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')",
1584                             "addItemIDB complete");
1585   ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
1586                             "readItemIDB complete");
1587   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents2,
1588                                             get_value.c_str(), &output));
1589   EXPECT_STREQ("page2", output.c_str());
1590
1591   // Reset the document title, otherwise the next call will not see a change and
1592   // will hang waiting for it.
1593   EXPECT_TRUE(content::ExecuteScript(storage_contents1,
1594                                      "document.title = 'foo'"));
1595
1596   // Read through the first tag to ensure we have the second value.
1597   ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
1598                             "readItemIDB complete");
1599   EXPECT_TRUE(ExecuteScriptAndExtractString(storage_contents1,
1600                                             get_value.c_str(), &output));
1601   EXPECT_STREQ("page2", output.c_str());
1602
1603   // Now, let's confirm there is no database in the main browser and another
1604   // tag that doesn't share the same partition. Due to the IndexedDB API design,
1605   // open will succeed, but the version will be 1, since it creates the database
1606   // if it is not found. The two tags use database version 3, so we avoid
1607   // ambiguity.
1608   const char* script =
1609       "indexedDB.open('isolation').onsuccess = function(e) {"
1610       "  if (e.target.result.version == 1)"
1611       "    document.title = 'db not found';"
1612       "  else "
1613       "    document.title = 'error';"
1614       "}";
1615   ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0),
1616                             script, "db not found");
1617   ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found");
1618 }
1619
1620 // This test ensures that closing app window on 'loadcommit' does not crash.
1621 // The test launches an app with guest and closes the window on loadcommit. It
1622 // then launches the app window again. The process is repeated 3 times.
1623 // http://crbug.com/291278
1624 #if defined(OS_WIN)
1625 #define MAYBE_CloseOnLoadcommit DISABLED_CloseOnLoadcommit
1626 #else
1627 #define MAYBE_CloseOnLoadcommit CloseOnLoadcommit
1628 #endif
1629 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_CloseOnLoadcommit) {
1630   ExtensionTestMessageListener done_test_listener(
1631       "done-close-on-loadcommit", false);
1632   LoadAndLaunchPlatformApp("web_view/close_on_loadcommit");
1633   ASSERT_TRUE(done_test_listener.WaitUntilSatisfied());
1634 }
1635
1636 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny_TestDeny) {
1637   MediaAccessAPIDenyTestHelper("testDeny");
1638 }
1639
1640 IN_PROC_BROWSER_TEST_F(WebViewTest,
1641                        MediaAccessAPIDeny_TestDenyThenAllowThrows) {
1642   MediaAccessAPIDenyTestHelper("testDenyThenAllowThrows");
1643
1644 }
1645
1646 IN_PROC_BROWSER_TEST_F(WebViewTest,
1647                        MediaAccessAPIDeny_TestDenyWithPreventDefault) {
1648   MediaAccessAPIDenyTestHelper("testDenyWithPreventDefault");
1649 }
1650
1651 IN_PROC_BROWSER_TEST_F(WebViewTest,
1652                        MediaAccessAPIDeny_TestNoListenersImplyDeny) {
1653   MediaAccessAPIDenyTestHelper("testNoListenersImplyDeny");
1654 }
1655
1656 IN_PROC_BROWSER_TEST_F(WebViewTest,
1657                        MediaAccessAPIDeny_TestNoPreventDefaultImpliesDeny) {
1658   MediaAccessAPIDenyTestHelper("testNoPreventDefaultImpliesDeny");
1659 }
1660
1661 void WebViewTest::MediaAccessAPIAllowTestHelper(const std::string& test_name) {
1662   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
1663   ExtensionTestMessageListener launched_listener("Launched", false);
1664   LoadAndLaunchPlatformApp("web_view/media_access/allow");
1665   ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
1666
1667   content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1668   ASSERT_TRUE(embedder_web_contents);
1669   scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
1670   embedder_web_contents->SetDelegate(mock.get());
1671
1672   ExtensionTestMessageListener done_listener("TEST_PASSED", false);
1673   done_listener.set_failure_message("TEST_FAILED");
1674   EXPECT_TRUE(
1675       content::ExecuteScript(
1676           embedder_web_contents,
1677           base::StringPrintf("startAllowTest('%s')",
1678                              test_name.c_str())));
1679   ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1680
1681   mock->WaitForSetMediaPermission();
1682 }
1683
1684 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_Basic) {
1685   LoadAppWithGuest("web_view/context_menus/basic");
1686
1687   content::WebContents* guest_web_contents = GetGuestWebContents();
1688   content::WebContents* embedder = GetEmbedderWebContents();
1689   ASSERT_TRUE(embedder);
1690
1691   // 1. Basic property test.
1692   ExecuteScriptWaitForTitle(embedder, "checkProperties()", "ITEM_CHECKED");
1693
1694   // 2. Create a menu item and wait for created callback to be called.
1695   ExecuteScriptWaitForTitle(embedder, "createMenuItem()", "ITEM_CREATED");
1696
1697   // 3. Click the created item, wait for the click handlers to fire from JS.
1698   ExtensionTestMessageListener click_listener("ITEM_CLICKED", false);
1699   GURL page_url("http://www.google.com");
1700   // Create and build our test context menu.
1701   scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create(
1702       guest_web_contents, page_url, GURL(), GURL()));
1703
1704   // Look for the extension item in the menu, and execute it.
1705   int command_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;
1706   ASSERT_TRUE(menu->IsCommandIdEnabled(command_id));
1707   menu->ExecuteCommand(command_id, 0);
1708
1709   // Wait for embedder's script to tell us its onclick fired, it does
1710   // chrome.test.sendMessage('ITEM_CLICKED')
1711   ASSERT_TRUE(click_listener.WaitUntilSatisfied());
1712
1713   // 4. Update the item's title and verify.
1714   ExecuteScriptWaitForTitle(embedder, "updateMenuItem()", "ITEM_UPDATED");
1715   MenuItem::List items = GetItems();
1716   ASSERT_EQ(1u, items.size());
1717   MenuItem* item = items.at(0);
1718   EXPECT_EQ("new_title", item->title());
1719
1720   // 5. Remove the item.
1721   ExecuteScriptWaitForTitle(embedder, "removeItem()", "ITEM_REMOVED");
1722   MenuItem::List items_after_removal = GetItems();
1723   ASSERT_EQ(0u, items_after_removal.size());
1724
1725   // 6. Add some more items.
1726   ExecuteScriptWaitForTitle(
1727       embedder, "createThreeMenuItems()", "ITEM_MULTIPLE_CREATED");
1728   MenuItem::List items_after_insertion = GetItems();
1729   ASSERT_EQ(3u, items_after_insertion.size());
1730
1731   // 7. Test removeAll().
1732   ExecuteScriptWaitForTitle(embedder, "removeAllItems()", "ITEM_ALL_REMOVED");
1733   MenuItem::List items_after_all_removal = GetItems();
1734   ASSERT_EQ(0u, items_after_all_removal.size());
1735 }
1736
1737 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) {
1738   MediaAccessAPIAllowTestHelper("testAllow");
1739 }
1740
1741 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) {
1742   MediaAccessAPIAllowTestHelper("testAllowAndThenDeny");
1743 }
1744
1745 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowTwice) {
1746   MediaAccessAPIAllowTestHelper("testAllowTwice");
1747 }
1748
1749 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAsync) {
1750   MediaAccessAPIAllowTestHelper("testAllowAsync");
1751 }
1752
1753 // Checks that window.screenX/screenY/screenLeft/screenTop works correctly for
1754 // guests.
1755 IN_PROC_BROWSER_TEST_F(WebViewTest, ScreenCoordinates) {
1756   ASSERT_TRUE(RunPlatformAppTestWithArg(
1757       "platform_apps/web_view/common", "screen_coordinates"))
1758           << message_;
1759 }
1760
1761 #if defined(OS_CHROMEOS)
1762 IN_PROC_BROWSER_TEST_F(WebViewTest, ChromeVoxInjection) {
1763   EXPECT_FALSE(
1764       chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
1765
1766   ASSERT_TRUE(StartEmbeddedTestServer());
1767   content::WebContents* guest_web_contents = LoadGuest(
1768       "/extensions/platform_apps/web_view/chromevox_injection/guest.html",
1769       "web_view/chromevox_injection");
1770   ASSERT_TRUE(guest_web_contents);
1771
1772   chromeos::SpeechMonitor monitor;
1773   chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
1774       true, ash::A11Y_NOTIFICATION_NONE);
1775   EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
1776
1777   EXPECT_EQ("chrome vox test title", monitor.GetNextUtterance());
1778 }
1779 #endif
1780
1781 // Flaky on Windows. http://crbug.com/303966
1782 #if defined(OS_WIN)
1783 #define MAYBE_TearDownTest DISABLED_TearDownTest
1784 #else
1785 #define MAYBE_TearDownTest TearDownTest
1786 #endif
1787 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_TearDownTest) {
1788   ExtensionTestMessageListener first_loaded_listener("guest-loaded", false);
1789   const extensions::Extension* extension =
1790       LoadAndLaunchPlatformApp("web_view/teardown");
1791   ASSERT_TRUE(first_loaded_listener.WaitUntilSatisfied());
1792   apps::AppWindow* window = NULL;
1793   if (!GetAppWindowCount())
1794     window = CreateAppWindow(extension);
1795   else
1796     window = GetFirstAppWindow();
1797   CloseAppWindow(window);
1798
1799   // Load the app again.
1800   ExtensionTestMessageListener second_loaded_listener("guest-loaded", false);
1801   LoadAndLaunchPlatformApp("web_view/teardown");
1802   ASSERT_TRUE(second_loaded_listener.WaitUntilSatisfied());
1803 }
1804
1805 // In following GeolocationAPIEmbedderHasNoAccess* tests, embedder (i.e. the
1806 // platform app) does not have geolocation permission for this test.
1807 // No matter what the API does, geolocation permission would be denied.
1808 // Note that the test name prefix must be "GeolocationAPI".
1809 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessAllow) {
1810   TestHelper("testDenyDenies",
1811              "web_view/geolocation/embedder_has_no_permission",
1812              NEEDS_TEST_SERVER);
1813 }
1814
1815 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasNoAccessDeny) {
1816   TestHelper("testDenyDenies",
1817              "web_view/geolocation/embedder_has_no_permission",
1818              NEEDS_TEST_SERVER);
1819 }
1820
1821 // In following GeolocationAPIEmbedderHasAccess* tests, embedder (i.e. the
1822 // platform app) has geolocation permission
1823 //
1824 // Note that these test names must be "GeolocationAPI" prefixed (b/c we mock out
1825 // geolocation in this case).
1826 //
1827 // Also note that these are run separately because OverrideGeolocation() doesn't
1828 // mock out geolocation for multiple navigator.geolocation calls properly and
1829 // the tests become flaky.
1830 // GeolocationAPI* test 1 of 3.
1831 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessAllow) {
1832   TestHelper("testAllow",
1833              "web_view/geolocation/embedder_has_permission",
1834              NEEDS_TEST_SERVER);
1835 }
1836
1837 // GeolocationAPI* test 2 of 3.
1838 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPIEmbedderHasAccessDeny) {
1839   TestHelper("testDeny",
1840              "web_view/geolocation/embedder_has_permission",
1841              NEEDS_TEST_SERVER);
1842 }
1843
1844 // GeolocationAPI* test 3 of 3.
1845 IN_PROC_BROWSER_TEST_F(WebViewTest,
1846                        GeolocationAPIEmbedderHasAccessMultipleBridgeIdAllow) {
1847   TestHelper("testMultipleBridgeIdAllow",
1848              "web_view/geolocation/embedder_has_permission",
1849              NEEDS_TEST_SERVER);
1850 }
1851
1852 // Tests that
1853 // BrowserPluginGeolocationPermissionContext::CancelGeolocationPermissionRequest
1854 // is handled correctly (and does not crash).
1855 IN_PROC_BROWSER_TEST_F(WebViewTest, GeolocationAPICancelGeolocation) {
1856   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
1857   ASSERT_TRUE(RunPlatformAppTest(
1858         "platform_apps/web_view/geolocation/cancel_request")) << message_;
1859 }
1860
1861 IN_PROC_BROWSER_TEST_F(WebViewTest, DISABLED_GeolocationRequestGone) {
1862   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
1863   ASSERT_TRUE(RunPlatformAppTest(
1864         "platform_apps/web_view/geolocation/geolocation_request_gone"))
1865             << message_;
1866 }
1867
1868 IN_PROC_BROWSER_TEST_F(WebViewTest, ClearData) {
1869 #if defined(OS_WIN)
1870   // Flaky on XP bot http://crbug.com/282674
1871   if (base::win::GetVersion() <= base::win::VERSION_XP)
1872     return;
1873 #endif
1874
1875   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
1876   ASSERT_TRUE(RunPlatformAppTestWithArg(
1877       "platform_apps/web_view/common", "cleardata"))
1878           << message_;
1879 }
1880
1881 // This test is disabled on Win due to being flaky. http://crbug.com/294592
1882 #if defined(OS_WIN)
1883 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage
1884 #else
1885 #define MAYBE_ConsoleMessage ConsoleMessage
1886 #endif
1887 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ConsoleMessage) {
1888   ASSERT_TRUE(RunPlatformAppTestWithArg(
1889       "platform_apps/web_view/common", "console_messages"))
1890           << message_;
1891 }
1892
1893 IN_PROC_BROWSER_TEST_F(WebViewTest, DownloadPermission) {
1894   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
1895   content::WebContents* guest_web_contents =
1896       LoadGuest("/extensions/platform_apps/web_view/download/guest.html",
1897                 "web_view/download");
1898   ASSERT_TRUE(guest_web_contents);
1899
1900   // Replace WebContentsDelegate with mock version so we can intercept download
1901   // requests.
1902   content::WebContentsDelegate* delegate = guest_web_contents->GetDelegate();
1903   scoped_ptr<MockDownloadWebContentsDelegate>
1904       mock_delegate(new MockDownloadWebContentsDelegate(delegate));
1905   guest_web_contents->SetDelegate(mock_delegate.get());
1906
1907   // Start test.
1908   // 1. Guest requests a download that its embedder denies.
1909   EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
1910                                      "startDownload('download-link-1')"));
1911   mock_delegate->WaitForCanDownload(false); // Expect to not allow.
1912   mock_delegate->Reset();
1913
1914   // 2. Guest requests a download that its embedder allows.
1915   EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
1916                                      "startDownload('download-link-2')"));
1917   mock_delegate->WaitForCanDownload(true); // Expect to allow.
1918   mock_delegate->Reset();
1919
1920   // 3. Guest requests a download that its embedder ignores, this implies deny.
1921   EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
1922                                      "startDownload('download-link-3')"));
1923   mock_delegate->WaitForCanDownload(false); // Expect to not allow.
1924 }
1925
1926 // This test makes sure loading <webview> does not crash when there is an
1927 // extension which has content script whitelisted/forced.
1928 IN_PROC_BROWSER_TEST_F(WebViewTest, WhitelistedContentScript) {
1929   // Whitelist the extension for running content script we are going to load.
1930   extensions::ExtensionsClient::ScriptingWhitelist whitelist;
1931   const std::string extension_id = "imeongpbjoodlnmlakaldhlcmijmhpbb";
1932   whitelist.push_back(extension_id);
1933   extensions::ExtensionsClient::Get()->SetScriptingWhitelist(whitelist);
1934
1935   // Load the extension.
1936   const extensions::Extension* content_script_whitelisted_extension =
1937       LoadExtension(test_data_dir_.AppendASCII(
1938                         "platform_apps/web_view/extension_api/content_script"));
1939   ASSERT_TRUE(content_script_whitelisted_extension);
1940   ASSERT_EQ(extension_id, content_script_whitelisted_extension->id());
1941
1942   // Now load an app with <webview>.
1943   ExtensionTestMessageListener done_listener("TEST_PASSED", false);
1944   LoadAndLaunchPlatformApp("web_view/content_script_whitelisted");
1945   ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1946 }
1947
1948 IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentReady) {
1949   ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_ready"))
1950                   << message_;
1951 }
1952
1953 IN_PROC_BROWSER_TEST_F(WebViewTest, SetPropertyOnDocumentInteractive) {
1954   ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/document_interactive"))
1955                   << message_;
1956 }
1957
1958 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_HasPermissionAllow) {
1959   ASSERT_TRUE(
1960       RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
1961                                 "allowTest"))
1962           << message_;
1963 }
1964
1965 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_HasPermissionDeny) {
1966   ASSERT_TRUE(
1967       RunPlatformAppTestWithArg("platform_apps/web_view/speech_recognition_api",
1968                                 "denyTest"))
1969           << message_;
1970 }
1971
1972 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognitionAPI_NoPermission) {
1973   ASSERT_TRUE(
1974       RunPlatformAppTestWithArg("platform_apps/web_view/common",
1975                                 "speech_recognition_api_no_permission"))
1976           << message_;
1977 }
1978
1979 // Tests overriding user agent.
1980 IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent) {
1981   ASSERT_TRUE(RunPlatformAppTestWithArg(
1982               "platform_apps/web_view/common", "useragent")) << message_;
1983 }
1984
1985 IN_PROC_BROWSER_TEST_F(WebViewTest, UserAgent_NewWindow) {
1986   ASSERT_TRUE(RunPlatformAppTestWithArg(
1987               "platform_apps/web_view/common",
1988               "useragent_newwindow")) << message_;
1989 }
1990
1991 IN_PROC_BROWSER_TEST_F(WebViewTest, NoPermission) {
1992   ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/nopermission"))
1993                   << message_;
1994 }
1995
1996 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestAlertDialog) {
1997   TestHelper("testAlertDialog", "web_view/dialog", NO_TEST_SERVER);
1998 }
1999
2000 IN_PROC_BROWSER_TEST_F(WebViewTest, TestConfirmDialog) {
2001   TestHelper("testConfirmDialog", "web_view/dialog", NO_TEST_SERVER);
2002 }
2003
2004 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogCancel) {
2005   TestHelper("testConfirmDialogCancel", "web_view/dialog", NO_TEST_SERVER);
2006 }
2007
2008 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultCancel) {
2009   TestHelper("testConfirmDialogDefaultCancel",
2010              "web_view/dialog",
2011              NO_TEST_SERVER);
2012 }
2013
2014 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestConfirmDialogDefaultGCCancel) {
2015   TestHelper("testConfirmDialogDefaultGCCancel",
2016              "web_view/dialog",
2017              NO_TEST_SERVER);
2018 }
2019
2020 IN_PROC_BROWSER_TEST_F(WebViewTest, Dialog_TestPromptDialog) {
2021   TestHelper("testPromptDialog", "web_view/dialog", NO_TEST_SERVER);
2022 }
2023
2024 IN_PROC_BROWSER_TEST_F(WebViewTest, NoContentSettingsAPI) {
2025   // Load the extension.
2026   const extensions::Extension* content_settings_extension =
2027       LoadExtension(
2028           test_data_dir_.AppendASCII(
2029               "platform_apps/web_view/extension_api/content_settings"));
2030   ASSERT_TRUE(content_settings_extension);
2031   TestHelper("testPostMessageCommChannel", "web_view/shim", NO_TEST_SERVER);
2032 }
2033
2034 #if defined(ENABLE_PLUGINS)
2035 class WebViewPluginTest : public WebViewTest {
2036  protected:
2037   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
2038     WebViewTest::SetUpCommandLine(command_line);
2039
2040     // Append the switch to register the pepper plugin.
2041     // library name = <out dir>/<test_name>.<library_extension>
2042     // MIME type = application/x-ppapi-<test_name>
2043     base::FilePath plugin_dir;
2044     EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
2045
2046     base::FilePath plugin_lib = plugin_dir.Append(library_name);
2047     EXPECT_TRUE(base::PathExists(plugin_lib));
2048     base::FilePath::StringType pepper_plugin = plugin_lib.value();
2049     pepper_plugin.append(FILE_PATH_LITERAL(";application/x-ppapi-tests"));
2050     command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
2051                                      pepper_plugin);
2052   }
2053 };
2054
2055 IN_PROC_BROWSER_TEST_F(WebViewPluginTest, TestLoadPluginEvent) {
2056   TestHelper("testPluginLoadPermission", "web_view/shim", NO_TEST_SERVER);
2057 }
2058 #endif  // defined(ENABLE_PLUGINS)
2059
2060 class WebViewCaptureTest : public WebViewTest {
2061  public:
2062   WebViewCaptureTest() {}
2063   virtual ~WebViewCaptureTest() {}
2064   virtual void SetUp() OVERRIDE {
2065     EnablePixelOutput();
2066     WebViewTest::SetUp();
2067   }
2068 };
2069
2070 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestZoomAPI) {
2071   TestHelper("testZoomAPI", "web_view/shim", NO_TEST_SERVER);
2072 }
2073
2074 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI) {
2075   TestHelper("testFindAPI", "web_view/shim", NO_TEST_SERVER);
2076 }
2077
2078 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestFindAPI_findupdate) {
2079   TestHelper("testFindAPI_findupdate", "web_view/shim", NO_TEST_SERVER);
2080 }
2081
2082 // <webview> screenshot capture fails with ubercomp.
2083 // See http://crbug.com/327035.
2084 IN_PROC_BROWSER_TEST_F(WebViewCaptureTest,
2085                        DISABLED_Shim_ScreenshotCapture) {
2086   TestHelper("testScreenshotCapture", "web_view/shim", NO_TEST_SERVER);
2087 }