1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// found in the LICENSE file.
4cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/test/ash_test_views_delegate.h"
6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "ash/shell.h"
8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/public/test/web_contents_tester.h"
9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace ash {
11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)namespace test {
12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)AshTestViewsDelegate::AshTestViewsDelegate() {
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)AshTestViewsDelegate::~AshTestViewsDelegate() {
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)content::WebContents* AshTestViewsDelegate::CreateWebContents(
20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    content::BrowserContext* browser_context,
21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    content::SiteInstance* site_instance) {
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return content::WebContentsTester::CreateTestWebContents(browser_context,
23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                                           site_instance);
24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void AshTestViewsDelegate::OnBeforeWidgetInit(
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    views::Widget::InitParams* params,
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    views::internal::NativeWidgetDelegate* delegate) {
29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  TestViewsDelegate::OnBeforeWidgetInit(params, delegate);
30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (!params->parent && !params->context && ash::Shell::HasInstance()) {
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    // If the window has neither a parent nor a context add to the root.
33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    params->parent = ash::Shell::GetInstance()->GetPrimaryRootWindow();
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}  // namespace test
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}  // namespace ash
39