Home | History | Annotate | Download | only in cocoa
      1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h>
      6 
      7 #include "base/memory/ref_counted.h"
      8 #include "chrome/browser/profiles/profile.h"
      9 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h"
     10 #include "chrome/test/testing_profile.h"
     11 #include "content/browser/browser_thread.h"
     12 #include "content/browser/renderer_host/test_render_view_host.h"
     13 #include "content/browser/site_instance.h"
     14 #include "content/browser/tab_contents/test_tab_contents.h"
     15 #import "testing/gtest_mac.h"
     16 
     17 namespace {
     18 
     19 class BugReportWindowControllerUnittest : public RenderViewHostTestHarness {
     20 };
     21 
     22 // See http://crbug.com/29019 for why it's disabled.
     23 TEST_F(BugReportWindowControllerUnittest, DISABLED_ReportBugWithNewTabPageOpen) {
     24   BrowserThread ui_thread(BrowserThread::UI, MessageLoop::current());
     25   // Create a "chrome://newtab" test tab.  SiteInstance will be deleted when
     26   // tabContents is deleted.
     27   SiteInstance* instance =
     28       SiteInstance::CreateSiteInstance(profile_.get());
     29   TestTabContents* tabContents = new TestTabContents(profile_.get(),
     30                                                       instance);
     31   tabContents->controller().LoadURL(GURL("chrome://newtab"),
     32       GURL(), PageTransition::START_PAGE);
     33 
     34   BugReportWindowController* controller = [[BugReportWindowController alloc]
     35       initWithTabContents:tabContents
     36                   profile:profile_.get()];
     37 
     38   // The phishing report bug is stored at index 2 in the Report Bug dialog.
     39   [controller setBugTypeIndex:2];
     40   EXPECT_TRUE([controller isPhishingReport]);
     41   [controller setBugTypeIndex:1];
     42   EXPECT_FALSE([controller isPhishingReport]);
     43 
     44   // Make sure that the tab was correctly recorded.
     45   EXPECT_NSEQ(@"chrome://newtab/", [controller pageURL]);
     46   EXPECT_NSEQ(@"New Tab", [controller pageTitle]);
     47 
     48   // When we call "report bug" with non-empty tab contents, all menu options
     49   // should be available, and we should send screenshot by default.
     50   EXPECT_EQ([[controller bugTypeList] count], 8U);
     51   EXPECT_TRUE([controller sendScreenshot]);
     52 
     53   delete tabContents;
     54   [controller release];
     55 }
     56 
     57 // See http://crbug.com/29019 for why it's disabled.
     58 TEST_F(BugReportWindowControllerUnittest, DISABLED_ReportBugWithNoWindowOpen) {
     59   BugReportWindowController* controller = [[BugReportWindowController alloc]
     60       initWithTabContents:NULL
     61                   profile:profile_.get()];
     62 
     63   // Make sure that no page title or URL are recorded. Note that IB reports
     64   // empty textfields as NULL values.
     65   EXPECT_FALSE([controller pageURL]);
     66   EXPECT_FALSE([controller pageTitle]);
     67 
     68   // When we call "report bug" with empty tab contents, only menu options
     69   // that don't refer to a specific page should be available, and the send
     70   // screenshot option should be turned off.
     71   EXPECT_EQ([[controller bugTypeList] count], 4U);
     72   EXPECT_FALSE([controller sendScreenshot]);
     73 
     74   [controller release];
     75 }
     76 
     77 }  // namespace
     78 
     79