Back to index

lightning-sunbird  0.9+nobinonly
nsIEditSession.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   David Epstein <depstein@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 // File Overview....
00040 //
00041 // nsIEditSession.cpp : test implementations for nsIEditingSession interface
00042 //
00043 
00044 #include "stdafx.h"
00045 #include "testembed.h"
00046 #include "nsIEditSession.h"
00047 #include "QaUtils.h"
00048 #include "BrowserFrm.h"
00049 #include "BrowserImpl.h"
00050 #include "BrowserView.h"
00051 #include "Tests.h"
00052 #include "nsIEditor.h"
00053 
00054 #ifdef _DEBUG
00055 #define new DEBUG_NEW
00056 #undef THIS_FILE
00057 static char THIS_FILE[] = __FILE__;
00058 #endif
00059 
00061 // nsIEditSession
00062 
00063 CnsIEditSession::CnsIEditSession(nsIWebBrowser *mWebBrowser)
00064 {
00065        qaWebBrowser = mWebBrowser;
00066 }
00067 
00068 CnsIEditSession::~CnsIEditSession()
00069 {
00070 }
00071 
00072 nsIEditingSession * CnsIEditSession::GetEditSessionObject()
00073 {
00074     editingSession = do_GetInterface(qaWebBrowser);
00075     if (!editingSession) {
00076         QAOutput("Didn't get nsIEditingSession object.");
00077               return nsnull;
00078        }
00079 
00080     return (editingSession);
00081 }
00082 
00083 void CnsIEditSession::InitTest(PRInt16 displayMode)
00084 {
00085        editingSession = GetEditSessionObject();
00086        domWindow = GetTheDOMWindow(qaWebBrowser);
00087        if (editingSession) {
00088               rv = editingSession->Init(domWindow);
00089               RvTestResult(rv, "Init() test", displayMode);
00090               if (displayMode == 1)
00091                      RvTestResultDlg(rv, "Init() test", true);
00092               if (!domWindow)
00093                      QAOutput("Didn't get domWindow object for InitTest() test. Test failed.", displayMode);
00094        }
00095        else
00096               QAOutput("Didn't get editingSession object for InitTest() test. Test failed.", displayMode);
00097 }
00098 
00099 void CnsIEditSession::MakeWinEditTest(PRBool afterUriLoad, PRInt16 displayMode)
00100 {
00101        editingSession = GetEditSessionObject();
00102        domWindow = GetTheDOMWindow(qaWebBrowser);
00103        if (editingSession) {
00104               rv= editingSession->MakeWindowEditable(domWindow, "text", afterUriLoad);
00105               RvTestResult(rv, "MakeWindowEditable() test", displayMode);
00106               if (displayMode == 1)
00107                      RvTestResultDlg(rv, "MakeWindowEditable() test");
00108               if (!domWindow)
00109                      QAOutput("Didn't get domWindow object for MakeWindowEditable() test. Test failed.", displayMode);
00110        }
00111        else
00112               QAOutput("Didn't get editingSession object for MakeWindowEditable() test. Test failed.", 1);
00113 }
00114 
00115 void CnsIEditSession::WinIsEditTest(PRBool outIsEditable, PRInt16 displayMode)
00116 {
00117        editingSession = GetEditSessionObject();
00118        domWindow = GetTheDOMWindow(qaWebBrowser);
00119        if (editingSession) {
00120               rv = editingSession->WindowIsEditable(domWindow, &outIsEditable);
00121               RvTestResult(rv, "WindowIsEditable() test", displayMode);
00122               if (displayMode == 1)
00123                      RvTestResultDlg(rv, "WindowIsEditable() test");
00124               if (!domWindow)
00125                      QAOutput("Didn't get domWindow object for WindowIsEditable() test. Test failed.", displayMode);
00126               FormatAndPrintOutput("the outIsEditable boolean = ", outIsEditable, displayMode);
00127        }
00128        else
00129               QAOutput("Didn't get object(s) for WinIsEditTest() test. Test failed.", 1);
00130 }
00131 
00132 void CnsIEditSession::GetEditorWinTest(PRInt16 displayMode)
00133 {
00134        nsCOMPtr<nsIEditor> theEditor;
00135 //     nsIEditor *theEditor = nsnull;
00136        editingSession = GetEditSessionObject();
00137        domWindow = GetTheDOMWindow(qaWebBrowser);
00138        if (editingSession) {
00139               rv = editingSession->GetEditorForWindow(domWindow, getter_AddRefs(theEditor));
00140               RvTestResult(rv, "GetEditorForWindow() test", displayMode);
00141               if (displayMode == 1)
00142                      RvTestResultDlg(rv, "GetEditorForWindow() test");
00143               if (!domWindow)
00144                      QAOutput("Didn't get domWindow object for GetEditorForWindow() test. Test failed.", displayMode);
00145 
00146               if (!theEditor) 
00147                      QAOutput("Didn't get the Editor object.");
00148        }
00149        else
00150               QAOutput("Didn't get object(s) for WinIsEditTest() test. Test failed.", 1);
00151 }
00152 
00153 void CnsIEditSession::SetEditorWinTest(PRInt16 displayMode)
00154 {
00155        editingSession = GetEditSessionObject();
00156        domWindow = GetTheDOMWindow(qaWebBrowser);
00157        if (editingSession) {
00158               rv = editingSession->SetupEditorOnWindow(domWindow);
00159               RvTestResult(rv, "SetupEditorOnWindow() test", displayMode);
00160               if (displayMode == 1)
00161                      RvTestResultDlg(rv, "SetupEditorOnWindow() test");
00162               if (!domWindow)
00163                      QAOutput("Didn't get domWindow object for SetupEditorOnWindow() test. Test failed.", displayMode);
00164        }
00165        else
00166               QAOutput("Didn't get object(s) for SetEditorWinTest() test. Test failed.", 1);
00167 }
00168 
00169 void CnsIEditSession::TearEditorWinTest(PRInt16 displayMode)
00170 {
00171        editingSession = GetEditSessionObject();
00172        domWindow = GetTheDOMWindow(qaWebBrowser);
00173        if (editingSession) {
00174               rv = editingSession->TearDownEditorOnWindow(domWindow);
00175               RvTestResult(rv, "TearDownEditorOnWindow() test", displayMode);
00176               if (displayMode == 1)
00177                      RvTestResultDlg(rv, "TearDownEditorOnWindow() test");
00178               if (!domWindow)
00179                      QAOutput("Didn't get domWindow object for TearDownEditorOnWindow() test. Test failed.", displayMode);
00180        }
00181        else
00182               QAOutput("Didn't get object(s) for TearEditorWinTest() test. Test failed.", 1);
00183 }
00184 
00185 void CnsIEditSession::OnStartTests(UINT nMenuID)
00186 {
00187        switch(nMenuID)
00188        {
00189               case ID_INTERFACES_NSIEDITINGSESSION_RUNALLTESTS :
00190                      RunAllTests();
00191                      break;
00192               case ID_INTERFACES_NSIEDITINGSESSION_INIT :
00193                      InitTest(2);
00194                      break;
00195               case ID_INTERFACES_NSIEDITINGSESSION_MAKEWINDOWEDITABLE :
00196                      MakeWinEditTest(PR_FALSE, 2);
00197                      break;
00198               case ID_INTERFACES_NSIEDITINGSESSION_WINDOWISEDITABLE  :
00199                      WinIsEditTest(PR_TRUE, 2);
00200                      break;
00201               case ID_INTERFACES_NSIEDITINGSESSION_GETEDITORFORWINDOW :
00202                      GetEditorWinTest(2);
00203                      break;
00204               case ID_INTERFACES_NSIEDITINGSESSION_SETUPEDITORONWINDOW :
00205                      SetEditorWinTest(2);
00206                      break;
00207               case ID_INTERFACES_NSIEDITINGSESSION_TEARDOWNEDITORONWINDOW :
00208                      TearEditorWinTest(2);
00209                      break;
00210        }
00211 }
00212 
00213 void CnsIEditSession::RunAllTests()
00214 {
00215        InitTest(1);
00216        MakeWinEditTest(PR_FALSE, 1);
00217        WinIsEditTest(PR_TRUE, 1);
00218        GetEditorWinTest(1);
00219 //     SetEditorWinTest(1);         
00220        TearEditorWinTest(1);
00221 }
00222 
00224 // CnsIEditSession message handlers