12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/views/confirm_bubble_views.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/confirm_bubble.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/test/test_confirm_bubble_model.h"
97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/ui/views/constrained_window_views.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/test/views_test_base.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/widget.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using views::Widget;
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef views::ViewsTestBase ConfirmBubbleViewsTest;
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(ConfirmBubbleViewsTest, CreateAndClose) {
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Create parent widget, as confirm bubble must have an owner.
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<views::Widget> parent_widget(new Widget);
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  parent_widget->Init(params);
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  parent_widget->Show();
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Bubble owns the model.
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool model_deleted = false;
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestConfirmBubbleModel* model =
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      new TestConfirmBubbleModel(&model_deleted, NULL, NULL, NULL);
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ConfirmBubbleViews* bubble = new ConfirmBubbleViews(model);
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  gfx::NativeWindow parent = parent_widget->GetNativeWindow();
327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  CreateBrowserModalDialogViews(bubble, parent)->Show();
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Clean up.
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bubble->GetWidget()->CloseNow();
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  parent_widget->CloseNow();
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(model_deleted);
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
39